From de017e675a0c9e29da1d3415b0296b2b42c66799 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Wed, 4 Sep 2024 21:12:13 +0200 Subject: [PATCH] [Instrumentation] Do not attache line number to instrumented call debuginfo 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 --- .../lib/Transforms/Instrumentation/SanitizerCoverage.cpp | 2 +- .../Instrumentation/SanitizerCoverage/coverage-dbg.ll | 2 +- .../Instrumentation/SanitizerCoverage/coverage2-dbg.ll | 2 +- .../SanitizerCoverage/crit-edge-sancov.ll | 9 ++++----- .../Instrumentation/SanitizerCoverage/missing_dbg.ll | 5 ++--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index 6a89cee9aaf6cc..48d00cfb967126 100644 --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -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. diff --git a/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll b/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll index af2f586bf6f9c9..301446d7bed651 100644 --- a/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll @@ -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" diff --git a/llvm/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll b/llvm/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll index e4278d56a6e201..b2bdfe354d9b8b 100644 --- a/llvm/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll @@ -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 { diff --git a/llvm/test/Instrumentation/SanitizerCoverage/crit-edge-sancov.ll b/llvm/test/Instrumentation/SanitizerCoverage/crit-edge-sancov.ll index f42fa7139fd585..fdbad4df186f5e 100644 --- a/llvm/test/Instrumentation/SanitizerCoverage/crit-edge-sancov.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/crit-edge-sancov.ll @@ -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 diff --git a/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll b/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll index 21c6fcdb3a84b0..6a785b681f621a 100644 --- a/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll @@ -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: @@ -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)