Author: Orlando Cazalet-Hyams
Date: 2025-05-22T17:07:43+01:00
New Revision: 398a1ac821e01835257206cd3ccf2a71d3a333d6

URL: 
https://github.com/llvm/llvm-project/commit/398a1ac821e01835257206cd3ccf2a71d3a333d6
DIFF: 
https://github.com/llvm/llvm-project/commit/398a1ac821e01835257206cd3ccf2a71d3a333d6.diff

LOG: [KeyInstr][Clang] Static variable init atom (#134636)

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

RFC:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

Added: 
    clang/test/DebugInfo/KeyInstructions/init-static.cpp

Modified: 
    clang/lib/CodeGen/CGDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 18135384021e8..f4549ab3033b2 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -429,8 +429,10 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D,
   bool isCudaSharedVar = getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
                          D.hasAttr<CUDASharedAttr>();
   // If this value has an initializer, emit it.
-  if (D.getInit() && !isCudaSharedVar)
+  if (D.getInit() && !isCudaSharedVar) {
+    ApplyAtomGroup Grp(getDebugInfo());
     var = AddInitializerToStaticVarDecl(D, var);
+  }
 
   var->setAlignment(alignment.getAsAlign());
 

diff  --git a/clang/test/DebugInfo/KeyInstructions/init-static.cpp 
b/clang/test/DebugInfo/KeyInstructions/init-static.cpp
new file mode 100644
index 0000000000000..745303a3c9d58
--- /dev/null
+++ b/clang/test/DebugInfo/KeyInstructions/init-static.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only 
-emit-llvm -o -\
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+void g(int *a) {
+    // CHECK: %2 = load ptr, ptr %a.addr{{.*}}, !dbg [[G1R2:!.*]]
+    // CHECK: store ptr %2, ptr @_ZZ1gPiE1b{{.*}}, !dbg [[G1R1:!.*]]
+    static int &b = *a;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to