Skip to content

Commit a92afbf

Browse files
committed
[KeyInstr][Clang] Static variable init atom
This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. The Key Instructions project is introduced, including a "quick summary" section at the top which adds context for this PR, here: 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. The Clang-side work is demoed here: #130943
1 parent eef73d3 commit a92afbf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,10 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D,
428428
bool isCudaSharedVar = getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
429429
D.hasAttr<CUDASharedAttr>();
430430
// If this value has an initializer, emit it.
431-
if (D.getInit() && !isCudaSharedVar)
431+
if (D.getInit() && !isCudaSharedVar) {
432+
ApplyAtomGroup Grp(getDebugInfo());
432433
var = AddInitializerToStaticVarDecl(D, var);
434+
}
433435

434436
var->setAlignment(alignment.getAsAlign());
435437

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o -\
2+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
3+
4+
void g(int *a) {
5+
// CHECK: %2 = load ptr, ptr %a.addr{{.*}}, !dbg [[G1R2:!.*]]
6+
// CHECK: store ptr %2, ptr @_ZZ1gPiE1b{{.*}}, !dbg [[G1R1:!.*]]
7+
static int &b = *a;
8+
}
9+
10+
// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
11+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
12+

0 commit comments

Comments
 (0)