[PATCH] D22419: [CFG] Fix crash in thread sanitizer.

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 2 14:15:15 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL277522: [CFG] Fix crash finding destructor of lifetime-extended temporary. (authored by dcoughlin).

Changed prior to commit:
  https://reviews.llvm.org/D22419?vs=65545&id=66554#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22419

Files:
  cfe/trunk/lib/Analysis/CFG.cpp
  cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Index: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -5160,6 +5160,21 @@
 }  // 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 {
Index: cfe/trunk/lib/Analysis/CFG.cpp
===================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp
+++ cfe/trunk/lib/Analysis/CFG.cpp
@@ -3902,7 +3902,17 @@
     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();
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22419.66554.patch
Type: text/x-patch
Size: 1511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160802/fe31fd2b/attachment-0001.bin>


More information about the cfe-commits mailing list