<div dir="ltr"><div>Hi Alexandre,</div><div><br></div><div>Looks like this commit is causing crashes on darwin, can you take a look please? Here is a failing bot: <a href="http://lab.llvm.org:8080/green/job/clang-stage1-RA/1671/">http://lab.llvm.org:8080/green/job/clang-stage1-RA/1671/</a></div><div><br></div><div>Thanks!</div><div>Erik<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 5, 2019 at 11:23 AM Alexandre Ganea 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: aganea<br>
Date: Thu Sep  5 08:24:49 2019<br>
New Revision: 371080<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=371080&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=371080&view=rev</a><br>
Log:<br>
[DebugInfo] Add debug location to stubs generated by CGDeclCXX and mark them as artificial<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D66328" rel="noreferrer" target="_blank">https://reviews.llvm.org/D66328</a><br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenCXX/debug-info-atexit-stub.cpp<br>
    cfe/trunk/test/CodeGenCXX/debug-info-destroy-helper.cpp<br>
Modified:<br>
    cfe/trunk/include/clang/AST/GlobalDecl.h<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp<br>
    cfe/trunk/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp<br>
    cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/GlobalDecl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/GlobalDecl.h?rev=371080&r1=371079&r2=371080&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/GlobalDecl.h?rev=371080&r1=371079&r2=371080&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/GlobalDecl.h (original)<br>
+++ cfe/trunk/include/clang/AST/GlobalDecl.h Thu Sep  5 08:24:49 2019<br>
@@ -31,6 +31,7 @@ enum class DynamicInitKind : unsigned {<br>
   NoStub = 0,<br>
   Initializer,<br>
   AtExit,<br>
+  GlobalArrayDestructor<br>
 };<br>
<br>
 /// GlobalDecl - represents a global declaration. This can either be a<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=371080&r1=371079&r2=371080&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=371080&r1=371079&r2=371080&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Sep  5 08:24:49 2019<br>
@@ -1910,7 +1910,8 @@ StringRef CGDebugInfo::getDynamicInitial<br>
                                                  llvm::Function *InitFn) {<br>
   // If we're not emitting codeview, use the mangled name. For Itanium, this is<br>
   // arbitrary.<br>
-  if (!CGM.getCodeGenOpts().EmitCodeView)<br>
+  if (!CGM.getCodeGenOpts().EmitCodeView ||<br>
+      StubKind == DynamicInitKind::GlobalArrayDestructor)<br>
     return InitFn->getName();<br>
<br>
   // Print the normal qualified name for the variable, then break off the last<br>
@@ -1935,6 +1936,7 @@ StringRef CGDebugInfo::getDynamicInitial<br>
<br>
   switch (StubKind) {<br>
   case DynamicInitKind::NoStub:<br>
+  case DynamicInitKind::GlobalArrayDestructor:<br>
     llvm_unreachable("not an initializer");<br>
   case DynamicInitKind::Initializer:<br>
     OS << "`dynamic initializer for '";<br>
@@ -3569,7 +3571,8 @@ void CGDebugInfo::EmitFunctionStart(Glob<br>
   if (Name.startswith("\01"))<br>
     Name = Name.substr(1);<br>
<br>
-  if (!HasDecl || D->isImplicit() || D->hasAttr<ArtificialAttr>()) {<br>
+  if (!HasDecl || D->isImplicit() || D->hasAttr<ArtificialAttr>() ||<br>
+      (isa<VarDecl>(D) && GD.getDynamicInitKind() != DynamicInitKind::NoStub)) {<br>
     Flags |= llvm::DINode::FlagArtificial;<br>
     // Artificial functions should not silently reuse CurLoc.<br>
     CurLoc = SourceLocation();<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=371080&r1=371079&r2=371080&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=371080&r1=371079&r2=371080&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Thu Sep  5 08:24:49 2019<br>
@@ -247,6 +247,8 @@ llvm::Function *CodeGenFunction::createA<br>
<br>
   CGF.StartFunction(GlobalDecl(&VD, DynamicInitKind::AtExit),<br>
                     CGM.getContext().VoidTy, fn, FI, FunctionArgList());<br>
+  // Emit an artificial location for this function.<br>
+  auto AL = ApplyDebugLocation::CreateArtificial(CGF);<br>
<br>
   llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);<br>
<br>
@@ -642,8 +644,9 @@ void CodeGenFunction::GenerateCXXGlobalV<br>
<br>
   StartFunction(GlobalDecl(D, DynamicInitKind::Initializer),<br>
                 getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(),<br>
-                FunctionArgList(), D->getLocation(),<br>
-                D->getInit()->getExprLoc());<br>
+                FunctionArgList());<br>
+  // Emit an artificial location for this function.<br>
+  auto AL = ApplyDebugLocation::CreateArtificial(*this);<br>
<br>
   // Use guarded initialization if the global variable is weak. This<br>
   // occurs for, e.g., instantiated static data members and<br>
@@ -768,7 +771,10 @@ llvm::Function *CodeGenFunction::generat<br>
<br>
   CurEHLocation = VD->getBeginLoc();<br>
<br>
-  StartFunction(VD, getContext().VoidTy, fn, FI, args);<br>
+  StartFunction(GlobalDecl(VD, DynamicInitKind::GlobalArrayDestructor),<br>
+                getContext().VoidTy, fn, FI, args);<br>
+  // Emit an artificial location for this function.<br>
+  auto AL = ApplyDebugLocation::CreateArtificial(*this);<br>
<br>
   emitDestroy(addr, type, destroyer, useEHCleanupForArray);<br>
<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/debug-info-atexit-stub.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-atexit-stub.cpp?rev=371080&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-atexit-stub.cpp?rev=371080&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-atexit-stub.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-atexit-stub.cpp Thu Sep  5 08:24:49 2019<br>
@@ -0,0 +1,20 @@<br>
+// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited -o - | FileCheck %s<br>
+<br>
+struct a {<br>
+  ~a();<br>
+};<br>
+template <typename b> struct c : a {<br>
+  c(void (b::*)());<br>
+};<br>
+struct B {<br>
+  virtual void e();<br>
+};<br>
+c<B> *d() { static c<B> f(&B::e); return &f; }<br>
+<br>
+// CHECK: define internal void @"??__Ff@?1??d@@YAPEAU?$c@UB@@@@XZ@YAXXZ"()<br>
+// CHECK-SAME: !dbg ![[SUBPROGRAM:[0-9]+]] {<br>
+// CHECK: call void @"??1?$c@UB@@@@QEAA@XZ"(%struct.c* @"?f@?1??d@@YAPEAU?$c@UB@@@@XZ@4U2@A"), !dbg ![[LOCATION:[0-9]+]]<br>
+// CHECK-NEXT: ret void, !dbg ![[LOCATION]]<br>
+// CHECK: ![[SUBPROGRAM]] = distinct !DISubprogram(name: "`dynamic atexit destructor for 'f'"<br>
+// CHECK-SAME: flags: DIFlagArtificial<br>
+// CHECK: ![[LOCATION]] = !DILocation(line: 0, scope: ![[SUBPROGRAM]])<br>
\ No newline at end of file<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/debug-info-destroy-helper.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-destroy-helper.cpp?rev=371080&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-destroy-helper.cpp?rev=371080&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-destroy-helper.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-destroy-helper.cpp Thu Sep  5 08:24:49 2019<br>
@@ -0,0 +1,24 @@<br>
+// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited -o - | FileCheck %s<br>
+<br>
+struct b {<br>
+  b(char *);<br>
+  ~b();<br>
+};<br>
+struct a {<br>
+  ~a();<br>
+};<br>
+struct {<br>
+  b c;<br>
+  const a &d;<br>
+} e[]{nullptr, {}};<br>
+<br>
+// CHECK: define internal void @__cxx_global_array_dtor(i8* %0)<br>
+// CHECK-SAME: !dbg ![[SUBPROGRAM:[0-9]+]] {<br>
+// CHECK: arraydestroy.body<br>
+// CHECK: %arraydestroy.elementPast =<br>
+// CHECK-SAME: !dbg ![[LOCATION:[0-9]+]]<br>
+// CHECK: call void @"??1<unnamed-type-e>@@QEAA@XZ"(%struct.anon* %arraydestroy.element)<br>
+// CHECK-SAME: !dbg ![[LOCATION]]<br>
+// CHECK: ![[SUBPROGRAM]] = distinct !DISubprogram(name: "__cxx_global_array_dtor"<br>
+// CHECK-SAME: flags: DIFlagArtificial<br>
+// CHECK: ![[LOCATION]] = !DILocation(line: 0,<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp?rev=371080&r1=371079&r2=371080&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp?rev=371080&r1=371079&r2=371080&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp Thu Sep  5 08:24:49 2019<br>
@@ -29,25 +29,26 @@ template <typename U><br>
 A FooTpl<T>::sdm_tpl(sizeof(U) + sizeof(T));<br>
 template A FooTpl<int>::sdm_tpl<int>;<br>
<br>
-// CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_var_init",{{.*}} line: 15,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-NOKEXT: !DISubprogram(name: "__dtor_glob",{{.*}} line: 15,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_var_init.1",{{.*}} line: 16,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_array_dtor",{{.*}} line: 16,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-NOKEXT: !DISubprogram(name: "__dtor_array",{{.*}} line: 16,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-NOKEXT: !DISubprogram(name: "__dtor__ZZ3foovE4stat",{{.*}} line: 19,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_var_init",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-NOKEXT: !DISubprogram(name: "__dtor_glob",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_var_init.1",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_array_dtor",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-NOKEXT: !DISubprogram(name: "__dtor_array",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-NOKEXT: !DISubprogram(name: "__dtor__ZZ3foovE4stat",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
 // CHECK-NOKEXT: !DISubprogram({{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
<br>
 // CHECK-KEXT: !DISubprogram({{.*}} DISPFlagLocalToUnit | DISPFlagDefinition<br>
<br>
-// CHECK-MSVC: !DISubprogram(name: "`dynamic initializer for 'glob'",{{.*}} line: 15,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'glob'",{{.*}} line: 15,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-MSVC: !DISubprogram(name: "`dynamic initializer for 'array'",{{.*}} line: 16,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-MSVC: !DISubprogram(name: "__cxx_global_array_dtor",{{.*}} line: 16,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'array'",{{.*}} line: 16,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'stat'",{{.*}} line: 19,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "`dynamic initializer for 'glob'",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'glob'",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "`dynamic initializer for 'array'",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "__cxx_global_array_dtor",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'array'",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'stat'",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
<br>
 // MSVC does weird stuff when templates are involved, so we don't match exactly,<br>
 // but these names are reasonable.<br>
 // FIXME: These should not be marked DISPFlagLocalToUnit.<br>
-// CHECK-MSVC: !DISubprogram(name: "FooTpl<int>::`dynamic initializer for 'sdm_tpl<int>'",{{.*}} line: 29,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
-// CHECK-MSVC: !DISubprogram(name: "FooTpl<int>::`dynamic atexit destructor for 'sdm_tpl<int>'",{{.*}} line: 29,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "FooTpl<int>::`dynamic initializer for 'sdm_tpl<int>'",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(name: "FooTpl<int>::`dynamic atexit destructor for 'sdm_tpl<int>'",{{.*}} flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition<br>
+// CHECK-MSVC: !DISubprogram(linkageName: "_GLOBAL__sub_I_debug_info_global_ctor_dtor.cpp",{{.*}} flags: DIFlagArtificial<br>
\ No newline at end of file<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=371080&r1=371079&r2=371080&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=371080&r1=371079&r2=371080&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-line.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-line.cpp Thu Sep  5 08:24:49 2019<br>
@@ -314,7 +314,7 @@ void f25() {<br>
 // CHECK: [[DBG_F9]] = !DILocation(line: 1000,<br>
 // CHECK: [[DBG_F10_STORE]] = !DILocation(line: 1100,<br>
 // CHECK: [[DBG_GLBL_CTOR_B]] = !DILocation(line: 1200,<br>
-// CHECK: [[DBG_GLBL_DTOR_B]] = !DILocation(line: 1200,<br>
+// CHECK: [[DBG_GLBL_DTOR_B]] = !DILocation(line: 0,<br>
 // CHECK: [[DBG_F11]] = !DILocation(line: 1300,<br>
 // CHECK: [[DBG_F12]] = !DILocation(line: 1400,<br>
 // CHECK: [[DBG_F13]] = !DILocation(line: 1500,<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>