diff options
-rw-r--r-- | lib/StaticAnalyzer/Core/ExprEngineC.cpp | 6 | ||||
-rw-r--r-- | test/Analysis/misc-ps-region-store.cpp | 38 |
2 files changed, 42 insertions, 2 deletions
diff --git a/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/lib/StaticAnalyzer/Core/ExprEngineC.cpp index 00b2f4a6be..d5a5762e98 100644 --- a/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -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, diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp index 6d43509cdd..1252140110 100644 --- a/test/Analysis/misc-ps-region-store.cpp +++ b/test/Analysis/misc-ps-region-store.cpp @@ -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 +} |