diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2018-02-27 20:14:06 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2018-02-27 20:14:06 +0000 |
commit | 8cd7961a0af7914345ba9ab8583e7fe7b7367b47 (patch) | |
tree | c72a8a41b37b752231aa5d633cf2fcd492f090ca /clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | |
parent | b7f53df0c2b5f33e562de876f51a18eace0b4997 (diff) | |
download | bcm5719-llvm-8cd7961a0af7914345ba9ab8583e7fe7b7367b47.tar.gz bcm5719-llvm-8cd7961a0af7914345ba9ab8583e7fe7b7367b47.zip |
[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
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
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<TemporaryObjectConstructionContext>(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; |