From 8cd7961a0af7914345ba9ab8583e7fe7b7367b47 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Tue, 27 Feb 2018 20:14:06 +0000 Subject: [analyzer] Disable constructor inlining when lifetime extending through a field. Automatic destructors are missing in the CFG in situations like const int &x = C().x; For now it's better to disable construction inlining, because inlining constructors while doing nothing on destructors is very bad. Differential Revision: https://reviews.llvm.org/D43689 llvm-svn: 326240 --- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp') diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index 14b4569b9a5..6502af74a33 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -168,6 +168,18 @@ ExprEngine::getRegionForConstructedObject(const CXXConstructExpr *CE, break; } case ConstructionContext::TemporaryObjectKind: { + const auto *TOCC = cast(CC); + // See if we're lifetime-extended via our field. If so, take a note. + // Because automatic destructors aren't quite working in this case. + if (const auto *MTE = TOCC->getMaterializedTemporaryExpr()) { + if (const ValueDecl *VD = MTE->getExtendingDecl()) { + assert(VD->getType()->isReferenceType()); + if (VD->getType()->getPointeeType().getCanonicalType() != + MTE->GetTemporaryExpr()->getType().getCanonicalType()) { + CallOpts.IsTemporaryLifetimeExtendedViaSubobject = true; + } + } + } // TODO: Support temporaries lifetime-extended via static references. // They'd need a getCXXStaticTempObjectRegion(). CallOpts.IsTemporaryCtorOrDtor = true; -- cgit v1.2.3