This revision was automatically updated to reflect the committed changes. Closed by commit rL296646: [analyzer] pr32088: Don't destroy the temporary if its initializer causes… (authored by dcoughlin).
Changed prior to commit: https://reviews.llvm.org/D30499?vs=90178&id=90201#toc Repository: rL LLVM https://reviews.llvm.org/D30499 Files: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp cfe/trunk/test/Analysis/temporaries.cpp Index: cfe/trunk/test/Analysis/temporaries.cpp =================================================================== --- cfe/trunk/test/Analysis/temporaries.cpp +++ cfe/trunk/test/Analysis/temporaries.cpp @@ -493,3 +493,13 @@ 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); + }); + } +} Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -615,7 +615,15 @@ 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(); }
Index: cfe/trunk/test/Analysis/temporaries.cpp =================================================================== --- cfe/trunk/test/Analysis/temporaries.cpp +++ cfe/trunk/test/Analysis/temporaries.cpp @@ -493,3 +493,13 @@ 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); + }); + } +} Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -615,7 +615,15 @@ 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(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits