https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/134654
>From e8a5ebb08165c6d9b0ac6b518b4ad3d1abd1fa4b Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Mon, 7 Apr 2025 12:18:48 +0100 Subject: [PATCH 1/3] [NFC][KeyInstr][Clang] Add some additional tests 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: https://github.com/llvm/llvm-project/pull/130943 new.cpp: Check store of addr and value are both added to same atom cast.c: Check we look through casts multi-func.c Check the atom group number is reset between functions --- clang/test/DebugInfo/KeyInstructions/cast.c | 19 ++++++++++ .../DebugInfo/KeyInstructions/multi-func.c | 19 ---------- clang/test/DebugInfo/KeyInstructions/new.cpp | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 clang/test/DebugInfo/KeyInstructions/cast.c delete mode 100644 clang/test/DebugInfo/KeyInstructions/multi-func.c create mode 100644 clang/test/DebugInfo/KeyInstructions/new.cpp diff --git a/clang/test/DebugInfo/KeyInstructions/cast.c b/clang/test/DebugInfo/KeyInstructions/cast.c new file mode 100644 index 0000000000000..b89edcc3089fb --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/cast.c @@ -0,0 +1,19 @@ +// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +float g; +void a() { +// CHECK: %0 = load float, ptr @g{{.*}}, !dbg [[G1R3:!.*]] +// CHECK: %conv = fptosi float %0 to i32{{.*}}, !dbg [[G1R2:!.*]] +// CHECK: store i32 %conv, ptr %a{{.*}}, !dbg [[G1R1:!.*]] + int a = g; +// CHECK: ret{{.*}}, !dbg [[G2R1:!.*]] +} + +// CHECK: [[G1R3]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 3) +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) diff --git a/clang/test/DebugInfo/KeyInstructions/multi-func.c b/clang/test/DebugInfo/KeyInstructions/multi-func.c deleted file mode 100644 index 6e225eed81de8..0000000000000 --- a/clang/test/DebugInfo/KeyInstructions/multi-func.c +++ /dev/null @@ -1,19 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \ -// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank - -// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \ -// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank - -// Check atomGroup is reset to start at 1 in each function. - -int g; -// CHECK: store{{.*}}, !dbg [[AG:!.*]] -void a() { g = 0; } - -// CHECK: store{{.*}}, !dbg [[BG:!.*]] -void b() { g = 0; } - -// CHECK: [[A:!.*]] = distinct !DISubprogram(name: "a", -// CHECK: [[AG]] = !DILocation(line: 11, scope: [[A]], atomGroup: 1, atomRank: 1) -// CHECK: [[B:!.*]] = distinct !DISubprogram(name: "b", -// CHECK: [[BG]] = !DILocation(line: 14, scope: [[B]], atomGroup: 1, atomRank: 1) diff --git a/clang/test/DebugInfo/KeyInstructions/new.cpp b/clang/test/DebugInfo/KeyInstructions/new.cpp new file mode 100644 index 0000000000000..9476e311e746f --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/new.cpp @@ -0,0 +1,37 @@ +// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// Check both the addr-store and value-store are part of the same atom. + +void f(int x) { +// CHECK: %call = call noalias noundef nonnull ptr @_Znwm{{.*}}, !dbg [[G1R2_C12:!.*]] +// CHECK: %0 = load i32, ptr %x.addr{{.*}}, !dbg [[G1R2_C20:!.*]] +// CHECK: store i32 %0, ptr %call{{.*}}, !dbg [[G1R1_C12:!.*]] +// CHECK: store ptr %call, ptr %{{.*}}, !dbg [[G1R1_C8:!.*]] + int *n = new int(x); +// CHECK: %call1 = call noalias noundef nonnull ptr @_Znwm{{.*}}, !dbg [[G2R2_C7:!.*]] +// CHECK: %1 = load i32, ptr %x.addr{{.*}}, !dbg [[G2R2_C15:!.*]] +// CHECK: store i32 %1, ptr %call{{.*}}, !dbg [[G2R1_C7:!.*]] +// CHECK: store ptr %call1, ptr %{{.*}}, !dbg [[G2R1_C5:!.*]] + n = new int(x); +// CHECK: %2 = load i32, ptr %x.addr{{.*}}, !dbg [[G3R2:!.*]] +// CHECK: %3 = load ptr, ptr %n +// CHECK: store i32 %2, ptr %3{{.*}}, !dbg [[G3R1:!.*]] + *n = x; +// CHECK: ret void, !dbg [[G4R1:!.*]] +} + +// CHECK: [[G1R2_C12]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R2_C20]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1_C12]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G1R1_C8]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) + +// CHECK: [[G2R2_C7]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) +// CHECK: [[G2R2_C15]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) +// CHECK: [[G2R1_C7]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[G2R1_C5]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) + +// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2) +// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) + +// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) >From dbb2e52e46291d103118158cca4dcfc325760416 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 21 May 2025 17:20:08 +0100 Subject: [PATCH 2/3] cc1 --- clang/test/DebugInfo/KeyInstructions/cast.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/new.cpp | 2 +- clang/test/KeyInstructions/multi-func.c | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 clang/test/KeyInstructions/multi-func.c diff --git a/clang/test/DebugInfo/KeyInstructions/cast.c b/clang/test/DebugInfo/KeyInstructions/cast.c index b89edcc3089fb..1d935466f0028 100644 --- a/clang/test/DebugInfo/KeyInstructions/cast.c +++ b/clang/test/DebugInfo/KeyInstructions/cast.c @@ -1,7 +1,7 @@ -// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - \ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank float g; diff --git a/clang/test/DebugInfo/KeyInstructions/new.cpp b/clang/test/DebugInfo/KeyInstructions/new.cpp index 9476e311e746f..2a420124d579f 100644 --- a/clang/test/DebugInfo/KeyInstructions/new.cpp +++ b/clang/test/DebugInfo/KeyInstructions/new.cpp @@ -1,4 +1,4 @@ -// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - -Wno-unused-variable \ +// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - -Wno-unused-variable \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank // Check both the addr-store and value-store are part of the same atom. diff --git a/clang/test/KeyInstructions/multi-func.c b/clang/test/KeyInstructions/multi-func.c new file mode 100644 index 0000000000000..a3020589863d5 --- /dev/null +++ b/clang/test/KeyInstructions/multi-func.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \ +// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank + +// Check atomGroup is reset to start at 1 in each function. + +// CHECK: ret{{.*}}, !dbg [[AG:!.*]] +void a() {} + +// CHECK: ret{{.*}}, !dbg [[BG:!.*]] +void b() {} + +// CHECK: [[A:!.*]] = distinct !DISubprogram(name: "a", +// CHECK: [[AG]] = !DILocation({{.*}}, scope: [[A]], atomGroup: 1, atomRank: 1) +// CHECK: [[B:!.*]] = distinct !DISubprogram(name: "b", +// CHECK: [[BG]] = !DILocation({{.*}}, scope: [[B]], atomGroup: 1, atomRank: 1) >From db87963afdc0d502c62cc229e49209d493aa330a Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Tue, 3 Jun 2025 11:20:34 +0100 Subject: [PATCH 3/3] fixtests --- clang/test/DebugInfo/KeyInstructions/cast.c | 6 ++---- clang/test/DebugInfo/KeyInstructions/new.cpp | 5 +---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/clang/test/DebugInfo/KeyInstructions/cast.c b/clang/test/DebugInfo/KeyInstructions/cast.c index 1d935466f0028..64b6a6e773544 100644 --- a/clang/test/DebugInfo/KeyInstructions/cast.c +++ b/clang/test/DebugInfo/KeyInstructions/cast.c @@ -1,7 +1,7 @@ -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c++ %s -debug-info-kind=line-tables-only -emit-llvm -o - \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang_cc1 -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -gno-column-info -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank float g; @@ -10,10 +10,8 @@ void a() { // CHECK: %conv = fptosi float %0 to i32{{.*}}, !dbg [[G1R2:!.*]] // CHECK: store i32 %conv, ptr %a{{.*}}, !dbg [[G1R1:!.*]] int a = g; -// CHECK: ret{{.*}}, !dbg [[G2R1:!.*]] } // CHECK: [[G1R3]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 3) // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) diff --git a/clang/test/DebugInfo/KeyInstructions/new.cpp b/clang/test/DebugInfo/KeyInstructions/new.cpp index 2a420124d579f..5ac2cf31d1380 100644 --- a/clang/test/DebugInfo/KeyInstructions/new.cpp +++ b/clang/test/DebugInfo/KeyInstructions/new.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - -Wno-unused-variable \ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - -Wno-unused-variable \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank // Check both the addr-store and value-store are part of the same atom. @@ -18,7 +18,6 @@ void f(int x) { // CHECK: %3 = load ptr, ptr %n // CHECK: store i32 %2, ptr %3{{.*}}, !dbg [[G3R1:!.*]] *n = x; -// CHECK: ret void, !dbg [[G4R1:!.*]] } // CHECK: [[G1R2_C12]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) @@ -33,5 +32,3 @@ void f(int x) { // CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) - -// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits