Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -3564,7 +3564,8 @@ if (Name.startswith("\01")) Name = Name.substr(1); - if (!HasDecl || D->isImplicit() || D->hasAttr()) { + if (!HasDecl || D->isImplicit() || D->hasAttr() || + (isa(D) && GD.getDynamicInitKind() == DynamicInitKind::AtExit)) { Flags |= llvm::DINode::FlagArtificial; // Artificial functions should not silently reuse CurLoc. CurLoc = SourceLocation(); Index: lib/CodeGen/CGDeclCXX.cpp =================================================================== --- lib/CodeGen/CGDeclCXX.cpp +++ lib/CodeGen/CGDeclCXX.cpp @@ -247,6 +247,8 @@ CGF.StartFunction(GlobalDecl(&VD, DynamicInitKind::AtExit), CGM.getContext().VoidTy, fn, FI, FunctionArgList()); + // Emit an artificial location for this function. + auto AL = ApplyDebugLocation::CreateArtificial(CGF); llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr); @@ -769,6 +771,8 @@ CurEHLocation = VD->getBeginLoc(); StartFunction(VD, getContext().VoidTy, fn, FI, args); + // Emit an artificial location for this function. + auto AL = ApplyDebugLocation::CreateArtificial(*this); emitDestroy(addr, type, destroyer, useEHCleanupForArray); Index: test/CodeGenCXX/debug-info-atexit-stub.cpp =================================================================== --- test/CodeGenCXX/debug-info-atexit-stub.cpp +++ test/CodeGenCXX/debug-info-atexit-stub.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited -o - | FileCheck %s + +struct a { + ~a(); +}; +template struct c : a { + c(void (b::*)()); +}; +struct B { + virtual void e(); +}; +c *d() { static c f(&B::e); return &f; } + +// CHECK: define internal void @"??__Ff@?1??d@@YAPEAU?$c@UB@@@@XZ@YAXXZ"() +// CHECK-SAME: !dbg ![[SUBPROGRAM:[0-9]+]] { +// CHECK: call void @"??1?$c@UB@@@@QEAA@XZ"(%struct.c* @"?f@?1??d@@YAPEAU?$c@UB@@@@XZ@4U2@A"), !dbg ![[LOCATION:[0-9]+]] +// CHECK-NEXT: ret void, !dbg ![[LOCATION]] +// CHECK: ![[SUBPROGRAM]] = distinct !DISubprogram(name: "`dynamic atexit destructor for 'f'" +// CHECK-SAME: flags: DIFlagArtificial +// CHECK: ![[LOCATION]] = !DILocation(line: 0, scope: ![[SUBPROGRAM]]) \ No newline at end of file Index: test/CodeGenCXX/debug-info-destroy-helper.cpp =================================================================== --- test/CodeGenCXX/debug-info-destroy-helper.cpp +++ test/CodeGenCXX/debug-info-destroy-helper.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited -o - | FileCheck %s + +struct b { + b(char *); + ~b(); +}; +struct a { + ~a(); +}; +struct { + b c; + const a &d; +} e[]{nullptr, {}}; + +// CHECK: arraydestroy.body +// CHECK: %arraydestroy.elementPast = +// CHECK-SAME: !dbg ![[LOCATION:[0-9]+]] +// CHECK: call void @"??1@@QEAA@XZ"(%struct.anon* %arraydestroy.element) +// CHECK-SAME: !dbg ![[LOCATION]] +// CHECK: ![[LOCATION]] = !DILocation(line: 0, Index: test/CodeGenCXX/debug-info-global-ctor-dtor.cpp =================================================================== --- test/CodeGenCXX/debug-info-global-ctor-dtor.cpp +++ test/CodeGenCXX/debug-info-global-ctor-dtor.cpp @@ -30,24 +30,24 @@ template A FooTpl::sdm_tpl; // CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_var_init",{{.*}} line: 15,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition -// CHECK-NOKEXT: !DISubprogram(name: "__dtor_glob",{{.*}} line: 15,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition +// CHECK-NOKEXT: !DISubprogram(name: "__dtor_glob",{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition // CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_var_init.1",{{.*}} line: 16,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition // CHECK-NOKEXT: !DISubprogram(name: "__cxx_global_array_dtor",{{.*}} line: 16,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition -// CHECK-NOKEXT: !DISubprogram(name: "__dtor_array",{{.*}} line: 16,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition -// CHECK-NOKEXT: !DISubprogram(name: "__dtor__ZZ3foovE4stat",{{.*}} line: 19,{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition +// CHECK-NOKEXT: !DISubprogram(name: "__dtor_array",{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition +// CHECK-NOKEXT: !DISubprogram(name: "__dtor__ZZ3foovE4stat",{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition // CHECK-NOKEXT: !DISubprogram({{.*}} DISPFlagLocalToUnit | DISPFlagDefinition // CHECK-KEXT: !DISubprogram({{.*}} DISPFlagLocalToUnit | DISPFlagDefinition // CHECK-MSVC: !DISubprogram(name: "`dynamic initializer for 'glob'",{{.*}} line: 15,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition -// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'glob'",{{.*}} line: 15,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition +// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'glob'",{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition // CHECK-MSVC: !DISubprogram(name: "`dynamic initializer for 'array'",{{.*}} line: 16,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition // CHECK-MSVC: !DISubprogram(name: "__cxx_global_array_dtor",{{.*}} line: 16,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition -// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'array'",{{.*}} line: 16,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition -// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'stat'",{{.*}} line: 19,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition +// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'array'",{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition +// CHECK-MSVC: !DISubprogram(name: "`dynamic atexit destructor for 'stat'",{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition // MSVC does weird stuff when templates are involved, so we don't match exactly, // but these names are reasonable. // FIXME: These should not be marked DISPFlagLocalToUnit. // CHECK-MSVC: !DISubprogram(name: "FooTpl::`dynamic initializer for 'sdm_tpl'",{{.*}} line: 29,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition -// CHECK-MSVC: !DISubprogram(name: "FooTpl::`dynamic atexit destructor for 'sdm_tpl'",{{.*}} line: 29,{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition +// CHECK-MSVC: !DISubprogram(name: "FooTpl::`dynamic atexit destructor for 'sdm_tpl'",{{.*}}: DISPFlagLocalToUnit | DISPFlagDefinition \ No newline at end of file Index: test/CodeGenCXX/debug-info-line.cpp =================================================================== --- test/CodeGenCXX/debug-info-line.cpp +++ test/CodeGenCXX/debug-info-line.cpp @@ -314,7 +314,7 @@ // CHECK: [[DBG_F9]] = !DILocation(line: 1000, // CHECK: [[DBG_F10_STORE]] = !DILocation(line: 1100, // CHECK: [[DBG_GLBL_CTOR_B]] = !DILocation(line: 1200, -// CHECK: [[DBG_GLBL_DTOR_B]] = !DILocation(line: 1200, +// CHECK: [[DBG_GLBL_DTOR_B]] = !DILocation(line: 0, // CHECK: [[DBG_F11]] = !DILocation(line: 1300, // CHECK: [[DBG_F12]] = !DILocation(line: 1400, // CHECK: [[DBG_F13]] = !DILocation(line: 1500,