Skip to content

Commit

Permalink
[Instrumentation] Do not attache line number to instrumented call deb…
Browse files Browse the repository at this point in the history
…uginfo

Doing so makes sure instrumentation code doesn't interferes with with
prologue endpoint computation when generating debug information, as
prologue_endpoint computation skips over such instructions.

Fix #54873
  • Loading branch information
serge-sans-paille committed Sep 4, 2024
1 parent 0ef8e71 commit de017e6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
DebugLoc EntryLoc;
if (IsEntryBB) {
if (auto SP = F.getSubprogram())
EntryLoc = DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
EntryLoc = DILocation::get(SP->getContext(), 0, 0, SP);
// Keep static allocas and llvm.localescape calls in the entry block. Even
// if we aren't splitting the block, it's nice for allocas to be before
// calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

; Test that __sanitizer_cov_trace_pc_guard call has !dbg pointing to the opening { of A::f().
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr{{.*}}) #{{.*}}, !dbg [[A:!.*]]
; CHECK: [[A]] = !DILocation(line: 6, scope: !{{.*}})
; CHECK: [[A]] = !DILocation(line: 0, scope: !{{.*}})


target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ target triple = "x86_64-unknown-linux-gnu"
; CHECK: call void @__sanitizer_cov{{.*}}(ptr{{.*}}) #{{.*}}, !dbg [[A:!.*]]
; CHECK: call void @__sanitizer_cov{{.*}}(ptr{{.*}}) #{{.*}}, !dbg [[B:!.*]]
; CHECK: ret void
; CHECK: [[A]] = !DILocation(line: 1, scope: !{{.*}})
; CHECK: [[A]] = !DILocation(line: 0, scope: !{{.*}})
; CHECK: [[B]] = !DILocation(line: 3, column: 5, scope: !{{.*}})

define void @_Z3fooPi(ptr %a) #0 !dbg !4 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ define void @update_shadow(i1 %c) !dbg !3 {
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc() #[[ATTR0:[0-9]+]], !dbg [[DBG6:![0-9]+]]
; CHECK: entry.for.inc.i_crit_edge:
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc() #[[ATTR0]], !dbg [[DBG7:![0-9]+]]
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc() #[[ATTR0]], !dbg [[DBG6]]
; CHECK: if.end22.i:
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc() #[[ATTR0]], !dbg [[DBG8:![0-9]+]]
; CHECK: [[DBG6]] = !DILocation(line: 192, scope: !3)
; CHECK: [[DBG7]] = !DILocation(line: 0, scope: !3)
; CHECK: [[DBG8]] = !DILocation(line: 129, column: 2, scope: !3)
; CHECK-NEXT: call void @__sanitizer_cov_trace_pc() #[[ATTR0]], !dbg [[DBG7:![0-9]+]]
; CHECK: [[DBG6]] = !DILocation(line: 0, scope: !3)
; CHECK: [[DBG7]] = !DILocation(line: 129, column: 2, scope: !3)
entry:
br i1 %c, label %for.inc.i, label %if.end22.i

Expand Down
5 changes: 2 additions & 3 deletions llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ entry:
; CHECK-LABEL: @with_dbg
; CHECK-NEXT: entry:
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_) #1, !dbg [[DBG1:![0-9]+]]
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_ to i64), i64 4) to ptr)) #1, !dbg [[DBG2:![0-9]+]]
; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_ to i64), i64 4) to ptr)) #1, !dbg [[DBG1]]

define i32 @without_dbg(ptr %a, ptr %b) {
entry:
Expand Down Expand Up @@ -46,5 +46,4 @@ entry:
!6 = !DILocation(line: 192, scope: !3)
!7 = !DILocation(line: 0, scope: !3)

; CHECK: [[DBG1]] = !DILocation(line: 192, scope: !3)
; CHECK: [[DBG2]] = !DILocation(line: 0, scope: !3)
; CHECK: [[DBG1]] = !DILocation(line: 0, scope: !3)

0 comments on commit de017e6

Please sign in to comment.