mirror of
https://github.com/intel/llvm.git
synced 2026-01-19 01:15:50 +08:00
[analyzer] Fix for faulty namespace test in SmartPtrModelling
This patch: - Fixes how the std-namespace test is written in SmartPtrModelling (now accounts for functions with no Decl available) - Adds the smart pointer checker flag check where it was missing Differential Revision: https://reviews.llvm.org/D106296
This commit is contained in:
@@ -248,9 +248,12 @@ bool isStdBasicOstream(const Expr *E) {
|
||||
return hasStdClassWithName(RD, BASIC_OSTREAM_NAMES);
|
||||
}
|
||||
|
||||
static bool isStdFunctionCall(const CallEvent &Call) {
|
||||
return Call.getDecl() && Call.getDecl()->getDeclContext()->isStdNamespace();
|
||||
}
|
||||
|
||||
bool isStdOstreamOperatorCall(const CallEvent &Call) {
|
||||
if (Call.getNumArgs() != 2 ||
|
||||
!Call.getDecl()->getDeclContext()->isStdNamespace())
|
||||
if (Call.getNumArgs() != 2 || !isStdFunctionCall(Call))
|
||||
return false;
|
||||
const auto *FC = dyn_cast<SimpleFunctionCall>(&Call);
|
||||
if (!FC)
|
||||
@@ -265,6 +268,13 @@ bool isStdOstreamOperatorCall(const CallEvent &Call) {
|
||||
isStdBasicOstream(Call.getArgExpr(0));
|
||||
}
|
||||
|
||||
static bool isPotentiallyComparisionOpCall(const CallEvent &Call) {
|
||||
if (Call.getNumArgs() != 2 || !isStdFunctionCall(Call))
|
||||
return false;
|
||||
return smartptr::isStdSmartPtr(Call.getArgExpr(0)) ||
|
||||
smartptr::isStdSmartPtr(Call.getArgExpr(1));
|
||||
}
|
||||
|
||||
bool SmartPtrModeling::evalCall(const CallEvent &Call,
|
||||
CheckerContext &C) const {
|
||||
|
||||
@@ -272,14 +282,11 @@ bool SmartPtrModeling::evalCall(const CallEvent &Call,
|
||||
|
||||
// If any one of the arg is a unique_ptr, then
|
||||
// we can try this function
|
||||
if (Call.getNumArgs() == 2 &&
|
||||
Call.getDecl()->getDeclContext()->isStdNamespace())
|
||||
if (smartptr::isStdSmartPtr(Call.getArgExpr(0)) ||
|
||||
smartptr::isStdSmartPtr(Call.getArgExpr(1)))
|
||||
if (handleComparisionOp(Call, C))
|
||||
return true;
|
||||
if (ModelSmartPtrDereference && isPotentiallyComparisionOpCall(Call))
|
||||
if (handleComparisionOp(Call, C))
|
||||
return true;
|
||||
|
||||
if (isStdOstreamOperatorCall(Call))
|
||||
if (ModelSmartPtrDereference && isStdOstreamOperatorCall(Call))
|
||||
return handleOstreamOperator(Call, C);
|
||||
|
||||
if (Call.isCalled(StdSwapCall)) {
|
||||
|
||||
@@ -536,3 +536,10 @@ void testOstreamDoesntInvalidateGlobals(std::unique_ptr<int> P) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// The following test isn't really a "smart-ptr" test
|
||||
// It came up during a bug fix (D106296)
|
||||
void testCheckForFunctionsWithNoDecl(void (*bar)(bool, bool)) {
|
||||
// This should NOT crash.
|
||||
bar(true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user