Xiangling_L created this revision.
Xiangling_L added reviewers: hubert.reinterpretcast, yusra.syeda, jasonliu.
Herald added subscribers: cfe-commits, aprantl.
Herald added a project: clang.

Set the debug location for static init related functions on AIX(__dtor and 
__finalize) so we can generate valid debug info by invoking `-g` with clang or 
`-debug-info-kind=limited` with clang_cc1.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83702

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/aix-static-init-debug-info.cpp

Index: clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/aix-static-init-debug-info.cpp
@@ -0,0 +1,70 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -emit-llvm -x c++ \
+// RUN:     -debug-info-kind=limited -fno-use-cxa-atexit < %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -emit-llvm -x c++ \
+// RUN:     -debug-info-kind=limited -fno-use-cxa-atexit < %s | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK64 %s
+
+int a = 0;
+
+class X {
+public:
+  X() {
+    a = 1;
+  }
+  ~X() {
+    a = -1;
+  }
+};
+
+X v;
+
+// CHECK: define internal void @__cxx_global_var_init() [[ATTR:#[0-9]+]] !dbg ![[DBGVAR19:[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @_ZN1XC1Ev(%class.X* @v), !dbg ![[DBGVAR22:[0-9]+]]
+// CHECK:   %0 = call i32 @atexit(void ()* @__dtor_v) [[ATTR:#[0-9]+]], !dbg ![[DBGVAR22]]
+// CHECK:   ret void, !dbg ![[DBGVAR22]]
+// CHECK: }
+
+// CHECK: define internal void @__dtor_v() [[ATTR:#[0-9]+]] !dbg ![[DBGVAR34:[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @_ZN1XD1Ev(%class.X* @v), !dbg ![[DBGVAR35:[0-9]+]]
+// CHECK:   ret void, !dbg ![[DBGVAR35]]
+// CHECK: }
+
+// CHECK: define internal void @__finalize_v() [[ATTR:#[0-9]+]] !dbg ![[DBGVAR36:[0-9]+]] {
+// CHECK: entry:
+// CHECK:   %0 = call i32 @unatexit(void ()* @__dtor_v) [[ATTR:#[0-9]+]], !dbg ![[DBGVAR38:[0-9]+]]
+// CHECK:   %needs_destruct = icmp eq i32 %0, 0, !dbg ![[DBGVAR38]]
+// CHECK:   br i1 %needs_destruct, label %destruct.call, label %destruct.end, !dbg ![[DBGVAR38]]
+
+// CHECK: destruct.call:
+// CHECK:   call void @__dtor_v(), !dbg ![[DBGVAR38]]
+// CHECK:   br label %destruct.end, !dbg ![[DBGVAR38]]
+
+// CHECK: destruct.end:
+// CHECK:   ret void, !dbg ![[DBGVAR38]]
+// CHECK: }
+
+// CHECK: define void @__sinit80000000_clang_9da80ccf074143d177aee39644eda39d() [[ATTR:#[0-9]+]] !dbg ![[DBGVAR51:[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__cxx_global_var_init(), !dbg ![[DBGVAR52:[0-9]+]]
+// CHECK:   ret void
+// CHECK: }
+
+// CHECK: define void @__sterm80000000_clang_9da80ccf074143d177aee39644eda39d() [[ATTR:#[0-9]+]] !dbg ![[DBGVAR53:[0-9]+]] {
+// CHECK: entry:
+// CHECK:   call void @__finalize_v(), !dbg ![[DBGVAR54:[0-9]+]]
+// CHECK:   ret void
+// CHECK: }
+
+
+// CHECK: ![[DBGVAR19]] = distinct !DISubprogram(name: "__cxx_global_var_init", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 21, type: !{{[0-9]+}}, scopeLine: 21, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !{{[0-9]+}}, retainedNodes:  !{{[0-9]+}})
+// CHECK: ![[DBGVAR22]] = !DILocation(line: 21, column: 3, scope: ![[DBGVAR19]])
+// CHECK: ![[DBGVAR36]] = distinct !DISubprogram(linkageName: "__finalize_v", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 21, type: !{{[0-9]+}}, scopeLine: 21, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR38]] = !DILocation(line: 21, column: 3, scope: ![[DBGVAR36]])
+// CHECK: ![[DBGVAR51]] = distinct !DISubprogram(linkageName: "__sinit80000000_clang_9da80ccf074143d177aee39644eda39d", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR52]] = !DILocation(line: 0, scope: ![[DBGVAR51]])
+// CHECK: ![[DBGVAR53]] = distinct !DISubprogram(linkageName: "__sterm80000000_clang_9da80ccf074143d177aee39644eda39d", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !{{[0-9]+}}, retainedNodes: !{{[0-9]+}})
+// CHECK: ![[DBGVAR54]] = !DILocation(line: 0, scope: ![[DBGVAR53]])
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -4567,7 +4567,8 @@
   CodeGenFunction CGF(CGM);
 
   CGF.StartFunction(GlobalDecl(), CGM.getContext().VoidTy, StermFinalizer, FI,
-                    FunctionArgList());
+                    FunctionArgList(), D.getLocation(),
+                    D.getInit()->getExprLoc());
 
   // The unatexit subroutine unregisters __dtor functions that were previously
   // registered by the atexit subroutine. If the referenced function is found,
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===================================================================
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -246,7 +246,8 @@
   CodeGenFunction CGF(CGM);
 
   CGF.StartFunction(GlobalDecl(&VD, DynamicInitKind::AtExit),
-                    CGM.getContext().VoidTy, fn, FI, FunctionArgList());
+                    CGM.getContext().VoidTy, fn, FI, FunctionArgList(),
+                    VD.getLocation(), VD.getInit()->getExprLoc());
 
   llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to