[clang] abf3bd6 - [clang][DebugInfo] Fix verbose trap source line (#222456)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 10 04:23:57 PDT 2026
Author: Yaxun (Sam) Liu
Date: 2026-09-10T07:23:52-04:00
New Revision: abf3bd63bb37d00aa4cd8b5dad873e1140d06348
URL: https://github.com/llvm/llvm-project/commit/abf3bd63bb37d00aa4cd8b5dad873e1140d06348
DIFF: https://github.com/llvm/llvm-project/commit/abf3bd63bb37d00aa4cd8b5dad873e1140d06348.diff
LOG: [clang][DebugInfo] Fix verbose trap source line (#222456)
The artificial inline location for `__builtin_verbose_trap` used line
zero. As a result, the emitted trap could inherit the preceding source
line in DWARF line tables.
Keep the artificial trap-message frame while assigning the builtin
call's line and column to the trap instruction.
Added:
Modified:
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/DebugInfo/CXX/verbose-trap.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4598a8a54e1b..1e65a6a30c35e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4146,11 +4146,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
EmitTrapCall(Intrinsic::trap);
return RValue::get(nullptr);
case Builtin::BI__builtin_verbose_trap: {
- llvm::DILocation *TrapLocation = Builder.getCurrentDebugLocation();
+ llvm::DebugLoc CallLocation = Builder.getCurrentDebugLocation();
+ llvm::DILocation *TrapLocation = CallLocation;
if (getDebugInfo()) {
TrapLocation = getDebugInfo()->CreateTrapFailureMessageFor(
TrapLocation, *E->getArg(0)->tryEvaluateString(getContext()),
*E->getArg(1)->tryEvaluateString(getContext()));
+ // Keep the trap on the builtin's source line. A line-zero location would
+ // leave the trap attributed to the preceding line in the line table.
+ TrapLocation = llvm::DILocation::get(
+ getLLVMContext(), CallLocation.getLine(), CallLocation.getCol(),
+ TrapLocation->getScope(), TrapLocation->getInlinedAt());
}
ApplyDebugLocation ApplyTrapDI(*this, TrapLocation);
// Currently no attempt is made to prevent traps from being merged.
diff --git a/clang/test/DebugInfo/CXX/verbose-trap.cpp b/clang/test/DebugInfo/CXX/verbose-trap.cpp
index af5bd4119532a..bae945ad4fda4 100644
--- a/clang/test/DebugInfo/CXX/verbose-trap.cpp
+++ b/clang/test/DebugInfo/CXX/verbose-trap.cpp
@@ -25,7 +25,7 @@ char const constCat[] = "category2";
char const constMsg[] = "hello";
// CHECK: ![[SUBPROG14:.*]] = distinct !DISubprogram(name: "f0", linkageName: "_Z2f0v",
-// CHECK: ![[LOC17]] = !DILocation(line: 0, scope: ![[SUBPROG18:.*]], inlinedAt: ![[LOC20:.*]])
+// CHECK: ![[LOC17]] = !DILocation(line: [[@LINE+4]], column: 3, scope: ![[SUBPROG18:.*]], inlinedAt: ![[LOC20:.*]])
// CHECK: ![[SUBPROG18]] = distinct !DISubprogram(name: "__clang_trap_msg$category1$Argument_must_not_be_null", scope: ![[FILESCOPE]], file: ![[FILESCOPE]], type: !{{.*}}, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !{{.*}})
// CHECK: ![[LOC20]] = !DILocation(line: [[@LINE+2]], column: 3, scope: ![[SUBPROG14]])
void f0() {
@@ -33,10 +33,10 @@ void f0() {
}
// CHECK: ![[SUBPROG22:.*]] = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v",
-// CHECK: ![[LOC23]] = !DILocation(line: 0, scope: ![[SUBPROG18]], inlinedAt: ![[LOC24:.*]])
+// CHECK: ![[LOC23]] = !DILocation(line: [[@LINE+7]], column: 3, scope: ![[SUBPROG18]], inlinedAt: ![[LOC24:.*]])
// CHECK: ![[LOC24]] = !DILocation(line: [[@LINE+6]], column: 3, scope: ![[SUBPROG22]])
// CHECK: ![[SUBPROG_F1B:.*]] = distinct !DISubprogram(name: "f1_b", linkageName: "_Z4f1_bv",
-// CHECK: ![[LOC25]] = !DILocation(line: 0, scope: ![[SUBPROG26:.*]], inlinedAt: ![[LOC27:.*]])
+// CHECK: ![[LOC25]] = !DILocation(line: [[@LINE+7]], column: 3, scope: ![[SUBPROG26:.*]], inlinedAt: ![[LOC27:.*]])
// CHECK: ![[SUBPROG26]] = distinct !DISubprogram(name: "__clang_trap_msg$category2$hello", scope: ![[FILESCOPE]], file: ![[FILESCOPE]], type: !{{.*}}, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !{{.*}})
// CHECK: ![[LOC27]] = !DILocation(line: [[@LINE+5]], column: 3, scope: ![[SUBPROG_F1B]])
void f1() {
@@ -47,7 +47,7 @@ void f1_b() {
}
// CHECK: ![[SUBPROG32:.*]] = distinct !DISubprogram(name: "f2<constCat, constMsg>", linkageName: "_Z2f2IXadsoKcL_ZL8constCatEEEXadsoS0_L_ZL8constMsgEEEEvv",
-// CHECK: ![[LOC36]] = !DILocation(line: 0, scope: ![[SUBPROG26]], inlinedAt: ![[LOC37:.*]])
+// CHECK: ![[LOC36]] = !DILocation(line: [[@LINE+4]], column: 3, scope: ![[SUBPROG26]], inlinedAt: ![[LOC37:.*]])
// CHECK: ![[LOC37]] = !DILocation(line: [[@LINE+3]], column: 3, scope: ![[SUBPROG32]])
template <const char * const category, const char * const reason>
void f2() {
More information about the cfe-commits
mailing list