[PATCH] D54344: [Clang][CodeGen][CXX]: Workaround __attribute((no_destroy)) crash/incorrect code generation.

Kristina Brooks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 9 12:18:12 PST 2018


kristina updated this revision to Diff 173411.
kristina added a comment.

Revised (style/ordering).


https://reviews.llvm.org/D54344

Files:
  lib/CodeGen/CGDeclCXX.cpp


Index: lib/CodeGen/CGDeclCXX.cpp
===================================================================
--- lib/CodeGen/CGDeclCXX.cpp
+++ lib/CodeGen/CGDeclCXX.cpp
@@ -64,10 +64,19 @@
 /// static storage duration.
 static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
                             ConstantAddress addr) {
-  CodeGenModule &CGM = CGF.CGM;
+  // Workaround for a bug that causes a reference to a nonexistent
+  // destructor under odd circumstances, when attribute no_destroy
+  // is used. This code should not be reachable under normal 
+  // circumstances, this workaround simply checks for the attribute
+  // again and bails if it's present instead of following a path
+  // that's either going to assert or emit incorrect code if reached.
+  if (D.hasAttr<NoDestroyAttr>())
+    return;
 
   // FIXME:  __attribute__((cleanup)) ?
 
+  CodeGenModule &CGM = CGF.CGM;
+
   QualType type = D.getType();
   QualType::DestructionKind dtorKind = type.isDestructedType();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54344.173411.patch
Type: text/x-patch
Size: 998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181109/9551ee1f/attachment.bin>


More information about the cfe-commits mailing list