From: Ted Kremenek Date: Wed, 28 Nov 2012 01:49:01 +0000 (+0000) Subject: Fix another false positive due to a CXX temporary object appearing in a C initializer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1994e3993e5e2c606f4ab22563768af6f03dad30;p=clang Fix another false positive due to a CXX temporary object appearing in a C initializer. The stop-gap here is to just drop such objects when processing the InitListExpr. We still need a better solution. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168757 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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(*it), LCtx), - vals); + SVal V = state->getSVal(cast(*it), LCtx); + if (dyn_cast_or_null(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 . + +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 +}