Skip to content

Commit 94dc187

Browse files
committed
[KeyIntsr][Clang] Builtins alloca auto-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 eb19277 commit 94dc187

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size,
138138
if (CGF.CGM.stopAutoInit())
139139
return;
140140
auto *I = CGF.Builder.CreateMemSet(AI, Byte, Size, AlignmentInBytes);
141+
CGF.addInstToCurrentSourceAtom(I, nullptr);
141142
I->addAnnotationMetadata("auto-init");
142143
}
143144

clang/test/KeyInstructions/builtin.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=zero \
3+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
4+
5+
// RUN: %clang -gkey-instructions -x c %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=zero \
6+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
7+
8+
void fun() {
9+
// CHECK: %a = alloca ptr, align 8
10+
// CHECK: %0 = alloca i8, i64 4{{.*}}, !dbg [[G1R2:!.*]]
11+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G1R1:!.*]], !annotation
12+
// CHECK: store ptr %0, ptr %a{{.*}}, !dbg [[G1R1:!.*]]
13+
void *a = __builtin_alloca(4);
14+
15+
// CHECK: %1 = alloca i8, i64 4{{.*}}, !dbg [[G2R2:!.*]]
16+
// CHECK: call void @llvm.memset{{.*}}, !dbg [[G2R1:!.*]], !annotation
17+
// CHECK: store ptr %1, ptr %b{{.*}}, !dbg [[G2R1:!.*]]
18+
void *b = __builtin_alloca_with_align(4, 8);
19+
}
20+
21+
// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
22+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
23+
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
24+
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)

0 commit comments

Comments
 (0)