<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 25, 2015 at 8:33 AM, Saleem Abdulrasool <span dir="ltr"><<a href="mailto:abdulras@fb.com" target="_blank">abdulras@fb.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><a href="http://reviews.llvm.org/D7872" target="_blank">http://reviews.llvm.org/D7872</a><br>
<br>
Files:<br>
  lib/CodeGen/CGDebugInfo.cpp<br>
  test/CodeGenCXX/inline-dllexport-member.cpp<br>
<br>
Index: lib/CodeGen/CGDebugInfo.cpp<br>
===================================================================<br>
--- lib/CodeGen/CGDebugInfo.cpp<br>
+++ lib/CodeGen/CGDebugInfo.cpp<br>
</span>@@ -2376,9 +2376,15 @@<br>
<span class="">   // FIXME: Generalize this for even non-member global variables where the<br>
   // declaration and definition may have different lexical decl contexts, once<br>
   // we have support for emitting declarations of (non-member) global variables.<br>
-  VDContext = getContextDescriptor(<br>
-      dyn_cast<Decl>(VD->isStaticDataMember() ? VD->getLexicalDeclContext()<br>
-                                              : VD->getDeclContext()));<br>
+  const DeclContext *DC = VD->isStaticDataMember() ? VD->getLexicalDeclContext()<br>
+                                                   : VD->getDeclContext();<br>
</span>+  // When a record type contains an in-line initialization of a static data<br>
+  // member, and the record type is marked as __declspec(dllexport),</blockquote><div><br>I'd continue this with "an implicit definition of the member will be created in the record context" instead of the rest of the sentence below. The creation of the implicit definition (& where it's scoped) seems to be the interesting bit. Could also say "DWARF doesn't seem to have a nice way to describe this that consumers are likely to understand, so fake the 'normal' situation of a definition outside the class by putting the definition in the global scope"<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> the member<br>
+  // debug DeclContext will be a type, which will cause an assertion.  Hoist the<br>
+  // context to the global scope.<br>
+  if (DC->isRecord())<br>
+    DC = CGM.getContext().getTranslationUnitDecl();<br>
<span class="">+  VDContext = getContextDescriptor(dyn_cast<Decl>(DC));<br>
 }<br>
<br>
 llvm::DISubprogram<br>
</span>@@ -3171,6 +3177,7 @@<br>
<span class=""> CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) {<br>
   if (!D->isStaticDataMember())<br>
     return llvm::DIDerivedType();<br>
+<br>
   auto MI = StaticDataMemberCache.find(D->getCanonicalDecl());<br>
   if (MI != StaticDataMemberCache.end()) {<br>
     assert(MI->second && "Static data member declaration should still exist");<br>
Index: test/CodeGenCXX/inline-dllexport-member.cpp<br>
===================================================================<br>
--- /dev/null<br>
+++ test/CodeGenCXX/inline-dllexport-member.cpp<br>
</span>@@ -0,0 +1,11 @@<br>
<span class="">+// RUN: %clang_cc1 -triple i686-windows-gnu -fms-compatibility -g -emit-llvm %s -o - \<br>
+// RUN:    | FileCheck %s<br>
+<br>
+struct __declspec(dllexport) s {<br>
+  static const unsigned int ui = 0;<br>
+};<br>
+<br>
</span>+// CHECK: !5 = !{!"{{.*}}inline-dllexport-member.cpp",<br></blockquote><div><br>^ Probably not important? (what's this intended to check?)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+// CHECK: !8, {{.*}}, i32* @_ZN1s2uiE, {{.*}}} ; [ DW_TAG_variable ] [ui] [line 5] [def]<br>
+// CHECK: !8 = !{!"0x29", !5} ; [ DW_TAG_file_type ] [{{.*}}inline-dllexport-member.cpp]<br></blockquote><div><br>Oh, I see, you're checking the specific file name. I don't think that's important. Simply checking that the scope of the DW_TAG_variable is a DW_TAG_file_type seems sufficient.<br><br>If possible, avoid using explicit metadata numbers - they can fluctuate/change for unrelated reasons (if we change other bits of debug info). So try to match the number using a FileCheck match ([[SCOPE:![^,]*]] - providing enough context in the DW_TAG_variable match line to ensure you get the right metadata reference (the one for the scope, not the one for the type, etc)) and then verify that:<br><br>[[SCOPE]] = {{.*}} ; [ DW_TAG_file_type ]<br><br>would be sufficient, I think.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">+<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
</div></div></blockquote></div><br></div></div>