Skip to content

Commit f65c762

Browse files
committed
[KeyInstr][Clang] Aggregate init + copy
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: llvm#130943
1 parent 0443438 commit f65c762

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
23942394
}
23952395
}
23962396

2397-
auto Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
2397+
auto *Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
2398+
addInstToCurrentSourceAtom(Inst, nullptr);
23982399

23992400
// Determine the metadata to describe the position of any padding in this
24002401
// memcpy, as well as the TBAA tags for the members of the struct, in case

clang/test/KeyInstructions/agg.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
3+
// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank
4+
5+
typedef struct { int a, b, c; } Struct;
6+
void fun(Struct a) {
7+
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
8+
Struct b = a;
9+
}
10+
11+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
12+

clang/test/KeyInstructions/init-agg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// store locations to be included in the atom group.
1010

1111
int g;
12+
typedef struct { int a, b, c; } Struct;
13+
Struct g2;
1214
void a() {
1315
// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
1416
int A[] = { 1, 2, 3 };

0 commit comments

Comments
 (0)