https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/134641
>From 7c86cc1b0b0bfaba4c304a31b5b0f2a1f391ad63 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Thu, 3 Apr 2025 17:31:32 +0100 Subject: [PATCH 1/3] [KeyInstr][Clang] Catch 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: https://github.com/llvm/llvm-project/pull/130943 --- clang/lib/CodeGen/ItaniumCXXABI.cpp | 1 + .../DebugInfo/KeyInstructions/try-catch.cpp | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 clang/test/DebugInfo/KeyInstructions/try-catch.cpp diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index faa07024a6052..1041ae84dbdf1 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -5055,6 +5055,7 @@ void ItaniumCXXABI::emitBeginCatch(CodeGenFunction &CGF, // Emit the local. CodeGenFunction::AutoVarEmission var = CGF.EmitAutoVarAlloca(*CatchParam); + ApplyAtomGroup Grp(CGF.getDebugInfo()); InitCatchParam(CGF, *CatchParam, var.getObjectAddress(CGF), S->getBeginLoc()); CGF.EmitAutoVarCleanups(var); } diff --git a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp new file mode 100644 index 0000000000000..3d1080aca2f07 --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp @@ -0,0 +1,20 @@ +// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - -fexceptions \ +// RUN: | FileCheck %s + +void except() { + // FIXME(OCH): Should `store i32 32, ptr %exception` be key? + throw 32; +} + +void attempt() { + try { except(); } +// CHECK: catch: +// CHECK: %4 = call ptr @__cxa_begin_catch(ptr %exn) +// CHECK: %5 = load i32{{.*}}, !dbg [[G1R2:!.*]] +// CHECK: store i32 %5, ptr %e{{.*}}, !dbg [[G1R1:!.*]] +// CHECK: call void @__cxa_end_catch() + catch (int e) { } +} + +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) >From 5d308ddf70afa9e7ec8382c0abada43f4296a486 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 21 May 2025 15:30:39 +0100 Subject: [PATCH 2/3] cc1 --- clang/test/DebugInfo/KeyInstructions/try-catch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp index 3d1080aca2f07..d2b458f361e11 100644 --- a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp +++ b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp @@ -1,4 +1,4 @@ -// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - -fexceptions \ +// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - -fexceptions -fcxx-exceptions \ // RUN: | FileCheck %s void except() { >From a2b11b1914d80d0796747b6f1045719893e2194f Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Tue, 27 May 2025 11:11:22 +0100 Subject: [PATCH 3/3] braces + add triple to test --- clang/lib/CodeGen/ItaniumCXXABI.cpp | 7 +++++-- clang/test/DebugInfo/KeyInstructions/try-catch.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 1041ae84dbdf1..5018a6b39b000 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -5055,8 +5055,11 @@ void ItaniumCXXABI::emitBeginCatch(CodeGenFunction &CGF, // Emit the local. CodeGenFunction::AutoVarEmission var = CGF.EmitAutoVarAlloca(*CatchParam); - ApplyAtomGroup Grp(CGF.getDebugInfo()); - InitCatchParam(CGF, *CatchParam, var.getObjectAddress(CGF), S->getBeginLoc()); + { + ApplyAtomGroup Grp(CGF.getDebugInfo()); + InitCatchParam(CGF, *CatchParam, var.getObjectAddress(CGF), + S->getBeginLoc()); + } CGF.EmitAutoVarCleanups(var); } diff --git a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp index d2b458f361e11..918eb4c97db9a 100644 --- a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp +++ b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - -fexceptions -fcxx-exceptions \ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - -fexceptions -fcxx-exceptions \ // RUN: | FileCheck %s void except() { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits