Hi jordan_rose,

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.

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

Files:
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Analysis/temporaries.cpp

Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -596,8 +596,6 @@
     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);
     }
     
Index: test/Analysis/temporaries.cpp
===================================================================
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -157,3 +157,39 @@
   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}}
+  }
+}
Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -596,8 +596,6 @@
     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);
     }
     
Index: test/Analysis/temporaries.cpp
===================================================================
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -157,3 +157,39 @@
   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}}
+  }
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to