]> granicus.if.org Git - clang/commitdiff
Fix another false positive due to a CXX temporary object appearing in a C initializer.
authorTed Kremenek <kremenek@apple.com>
Wed, 28 Nov 2012 01:49:01 +0000 (01:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 28 Nov 2012 01:49:01 +0000 (01:49 +0000)
The stop-gap here is to just drop such objects when processing the InitListExpr.
We still need a better solution.

Fixes <rdar://problem/12755044>.

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

lib/StaticAnalyzer/Core/ExprEngineC.cpp
test/Analysis/misc-ps-region-store.cpp

index 00b2f4a6bee997d48bc45f868c016e5973bc9c8e..d5a5762e98d6a20969153f5e0143243384e9d212 100644 (file)
@@ -581,8 +581,10 @@ void ExprEngine::VisitInitListExpr(const InitListExpr *IE,
     
     for (InitListExpr::const_reverse_iterator it = IE->rbegin(),
          ei = IE->rend(); it != ei; ++it) {
-      vals = getBasicVals().consVals(state->getSVal(cast<Expr>(*it), LCtx),
-                                     vals);
+      SVal V = state->getSVal(cast<Expr>(*it), LCtx);
+      if (dyn_cast_or_null<CXXTempObjectRegion>(V.getAsRegion()))
+        V = UnknownVal();
+      vals = getBasicVals().consVals(V, vals);
     }
     
     B.generateNode(IE, Pred,
index 6d43509cdd0523ed4b09fb96366b8b2c7f92e528..125214011035b4ebcd174d1dec714626c57d8afc 100644 (file)
@@ -656,3 +656,41 @@ unsigned RDar12753384() {
   return w.x;
 }
 
+// This testcase tests whether we treat the anonymous union and union
+// the same way.  This previously resulted in a "return of stack address"
+// warning because the anonymous union resulting in a temporary object
+// getting put into the initializer.  We still aren't handling this correctly,
+// but now if a temporary object appears in an initializer we just ignore it.
+// Fixes <rdar://problem/12755044>.
+
+struct Rdar12755044_foo
+{
+    struct Rdar12755044_bar
+    {
+        union baz
+        {
+            int   i;
+        };
+    } aBar;
+};
+
+struct Rdar12755044_foo_anon
+{
+    struct Rdar12755044_bar
+    {
+        union
+        {
+            int   i;
+        };
+    } aBar;
+};
+
+const Rdar12755044_foo_anon *radar12755044_anon() {
+  static const Rdar12755044_foo_anon Rdar12755044_foo_list[] = { { { } } };
+  return Rdar12755044_foo_list; // no-warning
+}
+
+const Rdar12755044_foo *radar12755044() {
+  static const Rdar12755044_foo Rdar12755044_foo_list[] = { { { } } };
+  return Rdar12755044_foo_list; // no-warning
+}