r188059 - [analyzer] Enable usage of temporaries in InitListExprs

Pavel Labath labath at google.com
Fri Aug 9 00:46:29 PDT 2013


Author: labath
Date: Fri Aug  9 02:46:29 2013
New Revision: 188059

URL: http://llvm.org/viewvc/llvm-project?rev=188059&view=rev
Log:
[analyzer] Enable usage of temporaries in InitListExprs

Summary:
ExprEngine had code which specificaly disabled using CXXTempObjectRegions in
InitListExprs. This was a hack put in r168757 to silence a false positive.

The underlying problem seems to have been fixed in the mean time, as removing
this code doesn't seem to break anything. Therefore I propose to remove it and
solve PR16629 in the process.

Reviewers: jordan_rose

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1325

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
    cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=188059&r1=188058&r2=188059&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Fri Aug  9 02:46:29 2013
@@ -596,8 +596,6 @@ void ExprEngine::VisitInitListExpr(const
     for (InitListExpr::const_reverse_iterator it = IE->rbegin(),
          ei = IE->rend(); it != ei; ++it) {
       SVal V = state->getSVal(cast<Expr>(*it), LCtx);
-      if (dyn_cast_or_null<CXXTempObjectRegion>(V.getAsRegion()))
-        V = UnknownVal();
       vals = getBasicVals().consVals(V, vals);
     }
     

Modified: cfe/trunk/test/Analysis/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temporaries.cpp?rev=188059&r1=188058&r2=188059&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/temporaries.cpp (original)
+++ cfe/trunk/test/Analysis/temporaries.cpp Fri Aug  9 02:46:29 2013
@@ -157,3 +157,39 @@ void testStaticMaterializeTemporaryExpr(
   clang_analyzer_eval(threadDirectRef.value == 42); // expected-warning{{TRUE}}
 #endif
 }
+
+namespace PR16629 {
+  struct A {
+    explicit A(int* p_) : p(p_) {}
+    int* p;
+  };
+
+  extern void escape(const A*[]);
+  extern void check(int);
+
+  void callEscape(const A& a) {
+    const A* args[] = { &a };
+    escape(args);
+  }
+
+  void testNoWarning() {
+    int x;
+    callEscape(A(&x));
+    check(x); // Analyzer used to give a "x is uninitialized warning" here
+  }
+
+  void set(const A*a[]) {
+    *a[0]->p = 47;
+  }
+
+  void callSet(const A& a) {
+    const A* args[] = { &a };
+    set(args);
+  }
+
+  void testConsistency() {
+    int x;
+    callSet(A(&x));
+    clang_analyzer_eval(x == 47); // expected-warning{{TRUE}}
+  }
+}





More information about the cfe-commits mailing list