<div dir="ltr">Hi Adrian,<div><br></div><div>I'm taking a look at this and can't duplicate using the testcase you gave without your patch(es) applied. It's also causing asserts in other code as you can have the forward decl left around and the CU isn't a valid context.</div><div><br></div><div>Can you take a look/revert until you've got a different testcase? There's not enough information in the commit to construct one up for you.</div><div><br></div><div>Thanks!</div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 5, 2016 at 6:03 PM Adrian Prantl via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Fri Feb  5 19:59:09 2016<br>
New Revision: 259975<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=259975&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=259975&view=rev</a><br>
Log:<br>
Fix a crash when emitting dbeug info for forward-declared scoped enums.<br>
It is possible for enums to be created as part of their own<br>
declcontext. We need to cache a placeholder to avoid the type being<br>
created twice before hitting the cache.<br>
<br>
<rdar://problem/24493203><br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=259975&r1=259974&r2=259975&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=259975&r1=259974&r2=259975&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Feb  5 19:59:09 2016<br>
@@ -2051,13 +2051,25 @@ llvm::DIType *CGDebugInfo::CreateEnumTyp<br>
   // If this is just a forward declaration, construct an appropriately<br>
   // marked node and just return it.<br>
   if (isImportedFromModule || !ED->getDefinition()) {<br>
-    llvm::DIScope *EDContext = getDeclContextDescriptor(ED);<br>
     llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());<br>
+<br>
+    // It is possible for enums to be created as part of their own<br>
+    // declcontext. We need to cache a placeholder to avoid the type being<br>
+    // created twice before hitting the cache.<br>
+    llvm::DIScope *EDContext = DBuilder.createReplaceableCompositeType(<br>
+      llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0);<br>
+<br>
     unsigned Line = getLineNumber(ED->getLocation());<br>
     StringRef EDName = ED->getName();<br>
     llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(<br>
         llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,<br>
         0, Size, Align, llvm::DINode::FlagFwdDecl, FullName);<br>
+<br>
+    // Cache the enum type so it is available when building the declcontext<br>
+    // and replace the declcontect with the real thing.<br>
+    TypeCache[Ty].reset(RetTy);<br>
+    EDContext->replaceAllUsesWith(getDeclContextDescriptor(ED));<br>
+<br>
     ReplaceMap.emplace_back(<br>
         std::piecewise_construct, std::make_tuple(Ty),<br>
         std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp?rev=259975&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp?rev=259975&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-scoped-class.cpp Fri Feb  5 19:59:09 2016<br>
@@ -0,0 +1,15 @@<br>
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -std=c++11 \<br>
+// RUN:   -triple thumbv7-apple-ios %s -o - | FileCheck %s<br>
+<br>
+// This forward-declared scoped enum will be created while building its own<br>
+// declcontext. Make sure it is only emitted once.<br>
+<br>
+struct A {<br>
+  enum class Return;<br>
+  Return f1();<br>
+};<br>
+A::Return* f2() {}<br>
+<br>
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Return",<br>
+// CHECK-SAME:             flags: DIFlagFwdDecl,<br>
+// CHECK-NOT:              tag: DW_TAG_enumeration_type, name: "Return"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>