https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/134652
>From 9bfc7f9adab19ce5b8353f0b569a852b1e48c68a Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Fri, 4 Apr 2025 16:28:39 +0100 Subject: [PATCH 1/4] [KeyInstr][Clang] Ret 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/CGCall.cpp | 6 +- clang/lib/CodeGen/CGCleanup.cpp | 2 + clang/lib/CodeGen/CGStmt.cpp | 13 +++- clang/lib/CodeGen/CodeGenFunction.cpp | 16 ++++ clang/test/KeyInstructions/return-va-arg.c | 25 ++++++ clang/test/KeyInstructions/return.c | 90 ++++++++++++++++++++++ 6 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 clang/test/KeyInstructions/return-va-arg.c create mode 100644 clang/test/KeyInstructions/return.c diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index bd920a2e3f2dd..36f02b262385a 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3938,7 +3938,8 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, // Functions with no result always return void. if (!ReturnValue.isValid()) { - Builder.CreateRetVoid(); + auto *I = Builder.CreateRetVoid(); + addRetToOverrideOrNewSourceAtom(I, nullptr); return; } @@ -4118,6 +4119,9 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, if (RetDbgLoc) Ret->setDebugLoc(std::move(RetDbgLoc)); + + llvm::Value *Backup = RV ? Ret->getOperand(0) : nullptr; + addRetToOverrideOrNewSourceAtom(cast<llvm::ReturnInst>(Ret), Backup); } void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) { diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index 7e1c5b7da9552..7292dcd47172c 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -1118,6 +1118,8 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) { // Create the branch. llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock()); + // This is the primary instruction for this atom, acting in place of a ret. + addInstToCurrentSourceAtom(BI, nullptr); // Calculate the innermost active normal cleanup. EHScopeStack::stable_iterator diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 2696bc9cc379b..a0fb49d44998e 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -1594,6 +1594,7 @@ static bool isSwiftAsyncCallee(const CallExpr *CE) { /// if the function returns void, or may be missing one if the function returns /// non-void. Fun stuff :). void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { + ApplyAtomGroup Grp(getDebugInfo()); if (requiresReturnValueCheck()) { llvm::Constant *SLoc = EmitCheckSourceLocation(S.getBeginLoc()); auto *SLocPtr = @@ -1603,6 +1604,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr); assert(ReturnLocation.isValid() && "No valid return location"); Builder.CreateStore(SLocPtr, ReturnLocation); + //*OCH?*// } // Returning from an outlined SEH helper is UB, and we already warn on it. @@ -1669,16 +1671,19 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { // If this function returns a reference, take the address of the expression // rather than the value. RValue Result = EmitReferenceBindingToExpr(RV); - Builder.CreateStore(Result.getScalarVal(), ReturnValue); + auto *I = Builder.CreateStore(Result.getScalarVal(), ReturnValue); + addInstToCurrentSourceAtom(I, I->getValueOperand()); } else { switch (getEvaluationKind(RV->getType())) { case TEK_Scalar: { llvm::Value *Ret = EmitScalarExpr(RV); - if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) + if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect) { EmitStoreOfScalar(Ret, MakeAddrLValue(ReturnValue, RV->getType()), /*isInit*/ true); - else - Builder.CreateStore(Ret, ReturnValue); + } else { + auto *I = Builder.CreateStore(Ret, ReturnValue); + addInstToCurrentSourceAtom(I, I->getValueOperand()); + } break; } case TEK_Complex: diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 0356952f4f291..68e050569aec3 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -36,6 +36,7 @@ #include "clang/CodeGen/CGFunctionInfo.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" @@ -339,6 +340,15 @@ llvm::DebugLoc CodeGenFunction::EmitReturnBlock() { // later by the actual 'ret' instruction. llvm::DebugLoc Loc = BI->getDebugLoc(); Builder.SetInsertPoint(BI->getParent()); + + // Key Instructions: If there's only one `ret` then we want to put the + // instruction in the same source atom group as the store to the ret-value + // alloca and unconditional `br` to the return block that we're about to + // delete. It all comes from the same source (`return (value)`). + if (auto *DI = getDebugInfo(); DI && BI->getDebugLoc()) + DI->setRetInstSourceAtomOverride( + BI->getDebugLoc().get()->getAtomGroup()); + BI->eraseFromParent(); delete ReturnBlock.getBlock(); ReturnBlock = JumpDest(); @@ -1542,6 +1552,12 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn, Bypasses.Init(CGM, Body); } + // Finalize function debug info on exit. + auto Cleanup = llvm::make_scope_exit([this] { + if (CGDebugInfo *DI = getDebugInfo()) + DI->completeFunction(); + }); + // Emit the standard function prologue. StartFunction(GD, ResTy, Fn, FnInfo, Args, Loc, BodyRange.getBegin()); diff --git a/clang/test/KeyInstructions/return-va-arg.c b/clang/test/KeyInstructions/return-va-arg.c new file mode 100644 index 0000000000000..2864489afd738 --- /dev/null +++ b/clang/test/KeyInstructions/return-va-arg.c @@ -0,0 +1,25 @@ +// 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 + +typedef struct { + struct{} a; + double b; +} s1; + +s1 f(int z, ...) { + __builtin_va_list list; + __builtin_va_start(list, z); +// CHECK: vaarg.end: +// CHECK-NEXT: %vaarg.addr = phi ptr +// CHECK-NEXT: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]] +// CHECK-NEXT: {{.*}} = getelementptr{{.*}} +// CHECK-NEXT: [[LOAD:%.*]] = load double{{.*}}, !dbg [[G1R2:!.*]] +// CHECK-NEXT: ret double [[LOAD]], !dbg [[G1R1]] + return __builtin_va_arg(list, s1); +} + +// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) diff --git a/clang/test/KeyInstructions/return.c b/clang/test/KeyInstructions/return.c new file mode 100644 index 0000000000000..24c58450d37ed --- /dev/null +++ b/clang/test/KeyInstructions/return.c @@ -0,0 +1,90 @@ +// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S -emit-llvm -o - \ +// RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-CXX + +// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm -o - \ +// RUN: | FileCheck %s + +// Check the stores to `retval` allocas and branches to `return` block are in +// the same atom group. They are both rank 1, which could in theory introduce +// an extra step in some optimized code. This low risk currently feels an +// acceptable for keeping the code a bit simpler (as opposed to adding +// scaffolding to make the store rank 2). + +// Also check that in the case of a single return (no control flow) the +// return instruction inherits the atom group of the branch to the return +// block when the blocks get folded togather. + +#ifdef __cplusplus +#define nomangle extern "C" +#else +#define nomangle +#endif + +int g; +nomangle float a() { +// CHECK: float @a() + if (g) +// CHECK: if.then: +// CHECK-NEXT: %1 = load i32, ptr @g{{.*}}, !dbg [[G2R3:!.*]] +// CHECK-NEXT: %conv = sitofp i32 %1 to float{{.*}}, !dbg [[G2R2:!.*]] +// CHECK-NEXT: store float %conv, ptr %retval{{.*}}, !dbg [[G2R1:!.*]] +// CHECK-NEXT: br label %return{{.*}}, !dbg [[G2R1]] + return g; +// CHECK: if.end: +// CHECK-NEXT: store float 1.000000e+00, ptr %retval{{.*}}, !dbg [[G3R1:!.*]] +// CHECK-NEXT: br label %return, !dbg [[G3R1]] + +// CHECK: return: +// CHECK-NEXT: %2 = load float, ptr %retval{{.*}}, !dbg [[G4R2:!.*]] +// CHECK-NEXT: ret float %2{{.*}}, !dbg [[G4R1:!.*]] + return 1; +} + +// CHECK: void @b() +// CHECK: ret void{{.*}}, !dbg [[B_G1R1:!.*]] +nomangle void b() { return; } + +// CHECK: i32 @c() +// CHECK: %add = add{{.*}}, !dbg [[C_G1R2:!.*]] +// CHECK: ret i32 %add{{.*}}, !dbg [[C_G1R1:!.*]] +nomangle int c() { return g + 1; } + +// NOTE: (return) (g = 1) are two separate atoms. +// CHECK: i32 @d() +// CHECK: store{{.*}}, !dbg [[D_G2R1:!.*]] +// CHECK: ret i32 1{{.*}}, !dbg [[D_G1R1:!.*]] +nomangle int d() { return g = 1; } + +// The implicit return here get the line number of the closing brace; make it +// key to match existing behaviour. +// CHECK: ret void, !dbg [[E_G1R1:!.*]] +nomangle void e() {} + +#ifdef __cplusplus +// CHECK-CXX: ptr @_Z1fRi +int &f(int &r) { +// Include ctrl-flow to stop ret value store being elided. + if (r) +// CHECK-CXX: if.then: +// CHECK-CXX-NEXT: %2 = load ptr, ptr %r.addr{{.*}}, !dbg [[F_G2R2:!.*]] +// CHECK-CXX-NEXT: store ptr %2, ptr %retval{{.*}}, !dbg [[F_G2R1:!.*]] +// CHECK-CXX-NEXT: br label %return, !dbg [[F_G2R1:!.*]] + return r; + return g; +} +#endif + +// CHECK: [[G2R3]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 3) +// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) +// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) +// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) +// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[B_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[C_G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) +// CHECK: [[C_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[D_G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[D_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[E_G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK-CXX: [[F_G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) +// CHECK-CXX: [[F_G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) >From afc9a0533ae5e8d56fb77ce835b3238929d9b77d Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Fri, 4 Apr 2025 16:36:53 +0100 Subject: [PATCH 2/4] [KeyInstr][Clang] Update tests with ret atoms --- clang/test/DebugInfo/KeyInstructions/agg.c | 3 +++ clang/test/DebugInfo/KeyInstructions/assign-scalar.c | 3 +++ clang/test/DebugInfo/KeyInstructions/bitfield.cpp | 3 +++ clang/test/DebugInfo/KeyInstructions/complex.c | 3 +++ clang/test/DebugInfo/KeyInstructions/do.c | 3 +++ clang/test/DebugInfo/KeyInstructions/for.c | 3 +++ clang/test/DebugInfo/KeyInstructions/if.c | 3 +++ clang/test/DebugInfo/KeyInstructions/init-agg.c | 3 +++ clang/test/DebugInfo/KeyInstructions/init-member.cpp | 2 ++ clang/test/DebugInfo/KeyInstructions/init-scalar.c | 2 ++ clang/test/DebugInfo/KeyInstructions/init-static.cpp | 3 ++- clang/test/DebugInfo/KeyInstructions/switch.c | 3 +++ clang/test/DebugInfo/KeyInstructions/try-catch.cpp | 3 +++ clang/test/DebugInfo/KeyInstructions/while.c | 3 +++ clang/test/KeyInstructions/builtin.c | 3 +++ 15 files changed, 42 insertions(+), 1 deletion(-) diff --git a/clang/test/DebugInfo/KeyInstructions/agg.c b/clang/test/DebugInfo/KeyInstructions/agg.c index e52f26e13d09f..c6ffb744baa6c 100644 --- a/clang/test/DebugInfo/KeyInstructions/agg.c +++ b/clang/test/DebugInfo/KeyInstructions/agg.c @@ -24,6 +24,8 @@ void fun(Struct a) { // CHECK: %matins = insertelement <25 x float> %3, float 0.000000e+00, i64 0, !dbg [[G4R2:!.*]] // CHECK: store <25 x float> %matins, ptr @m{{.*}}, !dbg [[G4R1:!.*]] m[0][0] = 0; + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) @@ -32,3 +34,4 @@ void fun(Struct a) { // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/assign-scalar.c b/clang/test/DebugInfo/KeyInstructions/assign-scalar.c index 903402b6d698c..0cd06baa1a2e6 100644 --- a/clang/test/DebugInfo/KeyInstructions/assign-scalar.c +++ b/clang/test/DebugInfo/KeyInstructions/assign-scalar.c @@ -34,6 +34,8 @@ void fun() { // CHECK: %dec = add i64 %3, -1, !dbg [[G6R2:!.*]] // CHECK: store i64 %dec, ptr @g{{.*}}, !dbg [[G6R1:!.*]] g--; + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) @@ -46,3 +48,4 @@ void fun() { // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) // CHECK: [[G6R2]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 2) // CHECK: [[G6R1]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/bitfield.cpp b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp index b76e6ec3d9c99..7e0c03a4fad0f 100644 --- a/clang/test/DebugInfo/KeyInstructions/bitfield.cpp +++ b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp @@ -7,7 +7,10 @@ void foo(int x, S s) { // CHECK: %bf.set = or i8 %bf.clear, %bf.value, !dbg [[G1R2:!.*]] // CHECK: store i8 %bf.set, ptr %s, align 4, !dbg [[G1R1:!.*]] s.a = x; + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/complex.c b/clang/test/DebugInfo/KeyInstructions/complex.c index ff8557afb91e7..da0494e63a289 100644 --- a/clang/test/DebugInfo/KeyInstructions/complex.c +++ b/clang/test/DebugInfo/KeyInstructions/complex.c @@ -27,6 +27,8 @@ void test() { // CHECK: %add = fadd float %0, %1, !dbg [[G4R2:!.*]] // CHECK: store float %add, ptr getelementptr inbounds nuw ({ float, float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G4R1:!.*]] __imag ci = __imag ci + __imag ci; + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) @@ -37,3 +39,4 @@ void test() { // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/do.c b/clang/test/DebugInfo/KeyInstructions/do.c index 4b1f25e58c4d8..6d2aa1b6e0cd7 100644 --- a/clang/test/DebugInfo/KeyInstructions/do.c +++ b/clang/test/DebugInfo/KeyInstructions/do.c @@ -25,9 +25,12 @@ void a(int A) { // CHECK: %tobool = icmp ne i32 %dec, 0, !dbg [[G2R1:!.*]] // CHECK: br i1 %tobool, label %do.body, label %do.end, !dbg [[G3R1:!.*]], !llvm.loop do { } while (--A); + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/for.c b/clang/test/DebugInfo/KeyInstructions/for.c index dbca87d73c293..1830b28dc7926 100644 --- a/clang/test/DebugInfo/KeyInstructions/for.c +++ b/clang/test/DebugInfo/KeyInstructions/for.c @@ -27,6 +27,8 @@ void a(int A) { // CHECK: %inc = add{{.*}}, !dbg [[G4R2:!.*]] // CHECK: store i32 %inc, ptr %i{{.*}}, !dbg [[G4R1:!.*]] for (int i = 0; i < A; ++i) { } + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) @@ -35,3 +37,4 @@ void a(int A) { // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) // CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/if.c b/clang/test/DebugInfo/KeyInstructions/if.c index df7d10d6ee7b8..38c1fdf47299b 100644 --- a/clang/test/DebugInfo/KeyInstructions/if.c +++ b/clang/test/DebugInfo/KeyInstructions/if.c @@ -32,6 +32,8 @@ void a(int A) { if (int B = A; B) ; #endif + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) @@ -44,3 +46,4 @@ void a(int A) { // CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) // CHECK-CXX: [[G5R2]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 2) // CHECK-CXX: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-agg.c b/clang/test/DebugInfo/KeyInstructions/init-agg.c index de1f247bb2722..57cf105bec7b5 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-agg.c +++ b/clang/test/DebugInfo/KeyInstructions/init-agg.c @@ -33,6 +33,8 @@ void a() { // CHECK: store i8 -86, ptr %uninit{{.*}}, !dbg [[G5R1:!.*]], !annotation char uninit; // -ftrivial-auto-var-init=pattern + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) @@ -41,3 +43,4 @@ void a() { // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-member.cpp b/clang/test/DebugInfo/KeyInstructions/init-member.cpp index 5ccefd4064421..339b1600f92e3 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-member.cpp +++ b/clang/test/DebugInfo/KeyInstructions/init-member.cpp @@ -17,6 +17,8 @@ void fun() { // CHECK: store i32 1, ptr %x{{.*}}, !dbg [[G1R1:!.*]] // CHECK: store float 5.000000e+00, ptr %y{{.*}}, !dbg [[G2R1:!.*]] +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-scalar.c b/clang/test/DebugInfo/KeyInstructions/init-scalar.c index a86c029e47e8c..4e4814b5b5f19 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-scalar.c +++ b/clang/test/DebugInfo/KeyInstructions/init-scalar.c @@ -10,8 +10,10 @@ void a() { // CHECK: %add = add {{.*}}, !dbg [[G2R2:!.*]] // CHECK: store i32 %add, ptr %B, align 4, !dbg [[G2R1:!.*]] int B = 2 * A + 1; +// CHECK: ret{{.*}}, !dbg [[G3R1:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) +// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) diff --git a/clang/test/DebugInfo/KeyInstructions/init-static.cpp b/clang/test/DebugInfo/KeyInstructions/init-static.cpp index 745303a3c9d58..adf88d39ebfa1 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-static.cpp +++ b/clang/test/DebugInfo/KeyInstructions/init-static.cpp @@ -5,8 +5,9 @@ void g(int *a) { // CHECK: %2 = load ptr, ptr %a.addr{{.*}}, !dbg [[G1R2:!.*]] // CHECK: store ptr %2, ptr @_ZZ1gPiE1b{{.*}}, !dbg [[G1R1:!.*]] static int &b = *a; +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) - +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/switch.c b/clang/test/DebugInfo/KeyInstructions/switch.c index dbfc4a44d271c..b674f2a63016a 100644 --- a/clang/test/DebugInfo/KeyInstructions/switch.c +++ b/clang/test/DebugInfo/KeyInstructions/switch.c @@ -41,6 +41,8 @@ void a(int A, int B) { } break; default: break; } + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) @@ -49,3 +51,4 @@ void a(int A, int B) { // CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp index d2b458f361e11..dcf4022d39105 100644 --- a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp +++ b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp @@ -14,7 +14,10 @@ void attempt() { // CHECK: store i32 %5, ptr %e{{.*}}, !dbg [[G1R1:!.*]] // CHECK: call void @__cxa_end_catch() catch (int e) { } + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/while.c b/clang/test/DebugInfo/KeyInstructions/while.c index d876bd1d93792..b501c714161c1 100644 --- a/clang/test/DebugInfo/KeyInstructions/while.c +++ b/clang/test/DebugInfo/KeyInstructions/while.c @@ -26,9 +26,12 @@ void a(int A) { // CHECK: %tobool = icmp ne i32 %dec, 0, !dbg [[G2R1:!.*]] // CHECK: br i1 %tobool, label %while.body, label %while.end, !dbg [[G3R1:!.*]] while (--A) { }; + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/KeyInstructions/builtin.c b/clang/test/KeyInstructions/builtin.c index 67a8017eeb236..1293916f35202 100644 --- a/clang/test/KeyInstructions/builtin.c +++ b/clang/test/KeyInstructions/builtin.c @@ -57,6 +57,8 @@ void fun() { // CHECK: call void @llvm.memset{{.*}}, !dbg [[G14R1:!.*]] __builtin___memset_chk(f4, 0, sizeof(float), -1); + +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) @@ -75,3 +77,4 @@ void fun() { // CHECK: [[G12R1]] = !DILocation({{.*}}, atomGroup: 12, atomRank: 1) // CHECK: [[G13R1]] = !DILocation({{.*}}, atomGroup: 13, atomRank: 1) // CHECK: [[G14R1]] = !DILocation({{.*}}, atomGroup: 14, atomRank: 1) +// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) >From 390d58b2b9607eb8165dd5aa8669e43f89fd1486 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 21 May 2025 17:09:46 +0100 Subject: [PATCH 3/4] fix rebase fallout - use new addInstToSpecificSourceAtom function, and fixup some tests --- clang/lib/CodeGen/CGCall.cpp | 16 +++++++++++----- clang/lib/CodeGen/CodeGenFunction.cpp | 17 +++++++---------- clang/lib/CodeGen/CodeGenFunction.h | 7 +++++-- clang/test/DebugInfo/KeyInstructions/agg.c | 2 +- .../DebugInfo/KeyInstructions/assign-scalar.c | 2 +- clang/test/DebugInfo/KeyInstructions/assign.c | 2 ++ .../test/DebugInfo/KeyInstructions/bitfield.cpp | 2 +- clang/test/DebugInfo/KeyInstructions/complex.c | 2 +- clang/test/DebugInfo/KeyInstructions/do.c | 2 +- clang/test/DebugInfo/KeyInstructions/for.c | 2 +- clang/test/DebugInfo/KeyInstructions/if.c | 2 +- clang/test/DebugInfo/KeyInstructions/init-agg.c | 2 +- .../test/DebugInfo/KeyInstructions/init-agg.cpp | 2 ++ .../DebugInfo/KeyInstructions/init-member.cpp | 2 +- .../DebugInfo/KeyInstructions/init-scalar.c | 4 ++-- .../DebugInfo/KeyInstructions/init-static.cpp | 6 +++--- clang/test/DebugInfo/KeyInstructions/switch.c | 2 +- .../DebugInfo/KeyInstructions/try-catch.cpp | 2 +- clang/test/DebugInfo/KeyInstructions/while.c | 2 +- clang/test/KeyInstructions/builtin.c | 2 +- 20 files changed, 45 insertions(+), 35 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 36f02b262385a..6e5cb71e059e2 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3921,9 +3921,9 @@ llvm::Value *CodeGenFunction::EmitCMSEClearRecord(llvm::Value *Src, return R; } -void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, - bool EmitRetDbgLoc, - SourceLocation EndLoc) { +void CodeGenFunction::EmitFunctionEpilog( + const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc, + uint64_t RetKeyInstructionsSourceAtom) { if (FI.isNoReturn()) { // Noreturn functions don't return. EmitUnreachable(EndLoc); @@ -3939,7 +3939,10 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, // Functions with no result always return void. if (!ReturnValue.isValid()) { auto *I = Builder.CreateRetVoid(); - addRetToOverrideOrNewSourceAtom(I, nullptr); + if (RetKeyInstructionsSourceAtom) + addInstToSpecificSourceAtom(I, nullptr, RetKeyInstructionsSourceAtom); + else + addInstToNewSourceAtom(I, nullptr); return; } @@ -4121,7 +4124,10 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, Ret->setDebugLoc(std::move(RetDbgLoc)); llvm::Value *Backup = RV ? Ret->getOperand(0) : nullptr; - addRetToOverrideOrNewSourceAtom(cast<llvm::ReturnInst>(Ret), Backup); + if (RetKeyInstructionsSourceAtom) + addInstToSpecificSourceAtom(Ret, Backup, RetKeyInstructionsSourceAtom); + else + addInstToNewSourceAtom(Ret, Backup); } void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) { diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 68e050569aec3..1ed9d1898bd60 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -340,15 +340,6 @@ llvm::DebugLoc CodeGenFunction::EmitReturnBlock() { // later by the actual 'ret' instruction. llvm::DebugLoc Loc = BI->getDebugLoc(); Builder.SetInsertPoint(BI->getParent()); - - // Key Instructions: If there's only one `ret` then we want to put the - // instruction in the same source atom group as the store to the ret-value - // alloca and unconditional `br` to the return block that we're about to - // delete. It all comes from the same source (`return (value)`). - if (auto *DI = getDebugInfo(); DI && BI->getDebugLoc()) - DI->setRetInstSourceAtomOverride( - BI->getDebugLoc().get()->getAtomGroup()); - BI->eraseFromParent(); delete ReturnBlock.getBlock(); ReturnBlock = JumpDest(); @@ -451,8 +442,14 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { // Reset the debug location to that of the simple 'return' expression, if any // rather than that of the end of the function's scope '}'. + uint64_t RetKeyInstructionsAtomGroup = Loc ? Loc->getAtomGroup() : 0; + llvm::errs() << "RetKeyInstructionsAtomGroup " << RetKeyInstructionsAtomGroup + << "\n"; + if (Loc) + llvm::errs() << *Loc << "\n"; ApplyDebugLocation AL(*this, Loc); - EmitFunctionEpilog(*CurFnInfo, EmitRetDbgLoc, EndLoc); + EmitFunctionEpilog(*CurFnInfo, EmitRetDbgLoc, EndLoc, + RetKeyInstructionsAtomGroup); EmitEndEHSpec(CurCodeDecl); assert(EHStack.empty() && diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 92e9ab8156ad2..d38a0628fe1eb 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2612,9 +2612,12 @@ class CodeGenFunction : public CodeGenTypeCache { const FunctionArgList &Args); /// EmitFunctionEpilog - Emit the target specific LLVM code to return the - /// given temporary. + /// given temporary. Specify the source location atom group (Key Instructions + /// debug info feature) for the `ret` using \p RetKeyInstructionsSourceAtom. + /// If it's 0, the `ret` will get added to a new source atom group. void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, - SourceLocation EndLoc); + SourceLocation EndLoc, + uint64_t RetKeyInstructionsSourceAtom); /// Emit a test that checks if the return value \p RV is nonnull. void EmitReturnValueCheck(llvm::Value *RV); diff --git a/clang/test/DebugInfo/KeyInstructions/agg.c b/clang/test/DebugInfo/KeyInstructions/agg.c index c6ffb744baa6c..7ba55e8563ccb 100644 --- a/clang/test/DebugInfo/KeyInstructions/agg.c +++ b/clang/test/DebugInfo/KeyInstructions/agg.c @@ -34,4 +34,4 @@ void fun(Struct a) { // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/assign-scalar.c b/clang/test/DebugInfo/KeyInstructions/assign-scalar.c index 0cd06baa1a2e6..f327a15b3ba0e 100644 --- a/clang/test/DebugInfo/KeyInstructions/assign-scalar.c +++ b/clang/test/DebugInfo/KeyInstructions/assign-scalar.c @@ -48,4 +48,4 @@ void fun() { // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) // CHECK: [[G6R2]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 2) // CHECK: [[G6R1]] = !DILocation({{.*}}, atomGroup: 6, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/assign.c b/clang/test/DebugInfo/KeyInstructions/assign.c index d2ce2dceed2f8..0e96dc82bb1ab 100644 --- a/clang/test/DebugInfo/KeyInstructions/assign.c +++ b/clang/test/DebugInfo/KeyInstructions/assign.c @@ -24,6 +24,7 @@ void fun() { // CHECK: %add = add i64 %1, 50, !dbg [[G4R2:!.*]] // CHECK: store i64 %add, ptr @g{{.*}}, !dbg [[G4R1:!.*]] g += 50; +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) @@ -32,3 +33,4 @@ void fun() { // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) // CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/bitfield.cpp b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp index 7e0c03a4fad0f..f41acdacd0dca 100644 --- a/clang/test/DebugInfo/KeyInstructions/bitfield.cpp +++ b/clang/test/DebugInfo/KeyInstructions/bitfield.cpp @@ -13,4 +13,4 @@ void foo(int x, S s) { // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/complex.c b/clang/test/DebugInfo/KeyInstructions/complex.c index da0494e63a289..3ed891af65d10 100644 --- a/clang/test/DebugInfo/KeyInstructions/complex.c +++ b/clang/test/DebugInfo/KeyInstructions/complex.c @@ -39,4 +39,4 @@ void test() { // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/do.c b/clang/test/DebugInfo/KeyInstructions/do.c index 6d2aa1b6e0cd7..d9af9bad044b6 100644 --- a/clang/test/DebugInfo/KeyInstructions/do.c +++ b/clang/test/DebugInfo/KeyInstructions/do.c @@ -33,4 +33,4 @@ void a(int A) { // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/for.c b/clang/test/DebugInfo/KeyInstructions/for.c index 1830b28dc7926..a99cf27e91464 100644 --- a/clang/test/DebugInfo/KeyInstructions/for.c +++ b/clang/test/DebugInfo/KeyInstructions/for.c @@ -37,4 +37,4 @@ void a(int A) { // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) // CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/if.c b/clang/test/DebugInfo/KeyInstructions/if.c index 38c1fdf47299b..d82ab139c818c 100644 --- a/clang/test/DebugInfo/KeyInstructions/if.c +++ b/clang/test/DebugInfo/KeyInstructions/if.c @@ -46,4 +46,4 @@ void a(int A) { // CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) // CHECK-CXX: [[G5R2]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 2) // CHECK-CXX: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-agg.c b/clang/test/DebugInfo/KeyInstructions/init-agg.c index 57cf105bec7b5..2ec70228c0654 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-agg.c +++ b/clang/test/DebugInfo/KeyInstructions/init-agg.c @@ -43,4 +43,4 @@ void a() { // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-agg.cpp b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp index 5446aae155d63..daf506b0866ac 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-agg.cpp +++ b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp @@ -36,6 +36,7 @@ void a() { // CHECK: store i8 -86, ptr %uninit{{.*}}, !dbg [[G5R1:!.*]], !annotation char uninit; // -ftrivial-auto-var-init=pattern +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) @@ -46,3 +47,4 @@ void a() { // CHECK: [[big_LINE]] = !DILocation(line: 32, scope: ![[#]]) // CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) // CHECK: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-member.cpp b/clang/test/DebugInfo/KeyInstructions/init-member.cpp index 339b1600f92e3..80ee32c6aa167 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-member.cpp +++ b/clang/test/DebugInfo/KeyInstructions/init-member.cpp @@ -21,4 +21,4 @@ void fun() { // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-scalar.c b/clang/test/DebugInfo/KeyInstructions/init-scalar.c index 4e4814b5b5f19..5e37a627afce9 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-scalar.c +++ b/clang/test/DebugInfo/KeyInstructions/init-scalar.c @@ -10,10 +10,10 @@ void a() { // CHECK: %add = add {{.*}}, !dbg [[G2R2:!.*]] // CHECK: store i32 %add, ptr %B, align 4, !dbg [[G2R1:!.*]] int B = 2 * A + 1; -// CHECK: ret{{.*}}, !dbg [[G3R1:!.*]] +// CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) -// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/init-static.cpp b/clang/test/DebugInfo/KeyInstructions/init-static.cpp index adf88d39ebfa1..be6c2a9f16585 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-static.cpp +++ b/clang/test/DebugInfo/KeyInstructions/init-static.cpp @@ -2,12 +2,12 @@ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank void g(int *a) { - // CHECK: %2 = load ptr, ptr %a.addr{{.*}}, !dbg [[G1R2:!.*]] - // CHECK: store ptr %2, ptr @_ZZ1gPiE1b{{.*}}, !dbg [[G1R1:!.*]] +// CHECK: %2 = load ptr, ptr %a.addr{{.*}}, !dbg [[G1R2:!.*]] +// CHECK: store ptr %2, ptr @_ZZ1gPiE1b{{.*}}, !dbg [[G1R1:!.*]] static int &b = *a; // CHECK: ret{{.*}}, !dbg [[RET:!.*]] } // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/switch.c b/clang/test/DebugInfo/KeyInstructions/switch.c index b674f2a63016a..4eea02aea2751 100644 --- a/clang/test/DebugInfo/KeyInstructions/switch.c +++ b/clang/test/DebugInfo/KeyInstructions/switch.c @@ -51,4 +51,4 @@ void a(int A, int B) { // CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) // CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp index dcf4022d39105..dfcb18c20e869 100644 --- a/clang/test/DebugInfo/KeyInstructions/try-catch.cpp +++ b/clang/test/DebugInfo/KeyInstructions/try-catch.cpp @@ -20,4 +20,4 @@ void attempt() { // CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2) // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/DebugInfo/KeyInstructions/while.c b/clang/test/DebugInfo/KeyInstructions/while.c index b501c714161c1..f26c0d48fb17d 100644 --- a/clang/test/DebugInfo/KeyInstructions/while.c +++ b/clang/test/DebugInfo/KeyInstructions/while.c @@ -34,4 +34,4 @@ void a(int A) { // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1) // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1) // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) diff --git a/clang/test/KeyInstructions/builtin.c b/clang/test/KeyInstructions/builtin.c index 1293916f35202..cb8b17f82c889 100644 --- a/clang/test/KeyInstructions/builtin.c +++ b/clang/test/KeyInstructions/builtin.c @@ -77,4 +77,4 @@ void fun() { // CHECK: [[G12R1]] = !DILocation({{.*}}, atomGroup: 12, atomRank: 1) // CHECK: [[G13R1]] = !DILocation({{.*}}, atomGroup: 13, atomRank: 1) // CHECK: [[G14R1]] = !DILocation({{.*}}, atomGroup: 14, atomRank: 1) -// CHECK: [[RET:!.*]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) +// CHECK: [[RET]] = !DILocation({{.*}}, atomGroup: [[#]], atomRank: [[#]]) >From a13e2d5558f2b5338f0dc815100a4eed7ace6691 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 21 May 2025 17:12:28 +0100 Subject: [PATCH 4/4] cc1 --- clang/test/KeyInstructions/return-va-arg.c | 4 ++-- clang/test/KeyInstructions/return.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/KeyInstructions/return-va-arg.c b/clang/test/KeyInstructions/return-va-arg.c index 2864489afd738..12f6e21a166a0 100644 --- a/clang/test/KeyInstructions/return-va-arg.c +++ b/clang/test/KeyInstructions/return-va-arg.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 typedef struct { diff --git a/clang/test/KeyInstructions/return.c b/clang/test/KeyInstructions/return.c index 24c58450d37ed..62a361fce08f3 100644 --- a/clang/test/KeyInstructions/return.c +++ b/clang/test/KeyInstructions/return.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 --check-prefixes=CHECK,CHECK-CXX -// 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 // Check the stores to `retval` allocas and branches to `return` block are in _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits