diff options
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 10 | ||||
-rw-r--r-- | clang/test/Analysis/temporaries.cpp | 10 |
2 files changed, 19 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 7d0c8b4bdf8..350992849e0 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -615,7 +615,15 @@ void ExprEngine::ProcessAutomaticObjDtor(const CFGAutomaticObjDtor Dtor, const MemRegion *Region = dest.castAs<loc::MemRegionVal>().getRegion(); if (varType->isReferenceType()) { - Region = state->getSVal(Region).getAsRegion()->getBaseRegion(); + const MemRegion *ValueRegion = state->getSVal(Region).getAsRegion(); + if (!ValueRegion) { + // FIXME: This should not happen. The language guarantees a presence + // of a valid initializer here, so the reference shall not be undefined. + // It seems that we're calling destructors over variables that + // were not initialized yet. + return; + } + Region = ValueRegion->getBaseRegion(); varType = cast<TypedValueRegion>(Region)->getValueType(); } diff --git a/clang/test/Analysis/temporaries.cpp b/clang/test/Analysis/temporaries.cpp index 49cf070177f..cc39201b0c3 100644 --- a/clang/test/Analysis/temporaries.cpp +++ b/clang/test/Analysis/temporaries.cpp @@ -493,3 +493,13 @@ namespace PR16629 { clang_analyzer_eval(x == 47); // expected-warning{{TRUE}} } } + +namespace PR32088 { + void testReturnFromStmtExprInitializer() { + // We shouldn't try to destroy the object pointed to by `obj' upon return. + const NonTrivial &obj = ({ + return; // no-crash + NonTrivial(42); + }); + } +} |