[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
This commit is contained in:
Orlando Cazalet-Hyams 2025-04-03 17:31:32 +01:00
parent c25359bdeb
commit 638b319d13
2 changed files with 21 additions and 0 deletions

View File

@ -5051,6 +5051,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);
}

View File

@ -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)