]> granicus.if.org Git - clang/commitdiff
[analyzer] Teach CallEventManager that CXXTemporaryObjectExpr is also a ctor.
authorJordan Rose <jordan_rose@apple.com>
Tue, 28 Aug 2012 20:52:21 +0000 (20:52 +0000)
committerJordan Rose <jordan_rose@apple.com>
Tue, 28 Aug 2012 20:52:21 +0000 (20:52 +0000)
Specifically, CallEventManager::getCaller was looking at the call site for
an inlined call and trying to see what kind of call it was, but it only
checked for CXXConstructExprClass. (It's not using an isa<> here to avoid
doing three more checks on the the statement class.)

This caused an unreachable when we actually did inline the constructor of a
temporary object.

PR13717

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162792 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CallEvent.cpp
test/Analysis/inline.cpp

index 1f86945fb342e9793685eed7e5a900c6f7faf806..32a66c3b27020c157469384d34eef140c7b1af43 100644 (file)
@@ -841,7 +841,8 @@ CallEventManager::getCaller(const StackFrameContext *CalleeCtx,
       return getSimpleCall(CE, State, CallerCtx);
 
     switch (CallSite->getStmtClass()) {
-    case Stmt::CXXConstructExprClass: {
+    case Stmt::CXXConstructExprClass:
+    case Stmt::CXXTemporaryObjectExprClass: {
       SValBuilder &SVB = State->getStateManager().getSValBuilder();
       const CXXMethodDecl *Ctor = cast<CXXMethodDecl>(CalleeCtx->getDecl());
       Loc ThisPtr = SVB.getCXXThis(Ctor, CalleeCtx);
index 573b1647a33385e4f1ee1d88161c765c868691c8..26b1035c06229f1b4e00d8424dd912faf2ce7ff9 100644 (file)
@@ -267,3 +267,20 @@ namespace OperatorNew {
     clang_analyzer_eval(obj->value == 42); // expected-warning{{UNKNOWN}}
   }
 }
+
+namespace TemporaryConstructor {
+  class BoolWrapper {
+  public:
+    BoolWrapper() {
+      clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+      value = true;
+    }
+    bool value;
+  };
+
+  void test() {
+    // PR13717 - Don't crash when a CXXTemporaryObjectExpr is inlined.
+    if (BoolWrapper().value)
+      return;
+  }
+}