r277522 - [CFG] Fix crash finding destructor of lifetime-extended temporary.
Devin Coughlin via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 2 14:07:24 PDT 2016
Author: dcoughlin
Date: Tue Aug 2 16:07:23 2016
New Revision: 277522
URL: http://llvm.org/viewvc/llvm-project?rev=277522&view=rev
Log:
[CFG] Fix crash finding destructor of lifetime-extended temporary.
Fix a crash under -Wthread-safety when finding the destructor for a
lifetime-extending reference.
A patch by Nandor Licker!
Differential Revision: https://reviews.llvm.org/D22419
Modified:
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=277522&r1=277521&r2=277522&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Aug 2 16:07:23 2016
@@ -3902,7 +3902,17 @@ CFGImplicitDtor::getDestructorDecl(ASTCo
case CFGElement::AutomaticObjectDtor: {
const VarDecl *var = castAs<CFGAutomaticObjDtor>().getVarDecl();
QualType ty = var->getType();
- ty = ty.getNonReferenceType();
+
+ // FIXME: See CFGBuilder::addLocalScopeForVarDecl.
+ //
+ // Lifetime-extending constructs are handled here. This works for a single
+ // temporary in an initializer expression.
+ if (ty->isReferenceType()) {
+ if (const Expr *Init = var->getInit()) {
+ ty = getReferenceInitTemporaryType(astContext, Init);
+ }
+ }
+
while (const ArrayType *arrayType = astContext.getAsArrayType(ty)) {
ty = arrayType->getElementType();
}
Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=277522&r1=277521&r2=277522&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Tue Aug 2 16:07:23 2016
@@ -5160,6 +5160,21 @@ void test3() {
} // end namespace GlobalAcquiredBeforeAfterTest
+namespace LifetimeExtensionText {
+
+struct Holder {
+ virtual ~Holder() throw() {}
+ int i = 0;
+};
+
+void test() {
+ // Should not crash.
+ const auto &value = Holder().i;
+}
+
+} // end namespace LifetimeExtensionTest
+
+
namespace LockableUnions {
union LOCKABLE MutexUnion {
More information about the cfe-commits
mailing list