[llvm] [Instrumentation] Mark instrumented calls as implicit (PR #106447)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 05:34:23 PDT 2024


https://github.com/serge-sans-paille updated https://github.com/llvm/llvm-project/pull/106447

>From de017e675a0c9e29da1d3415b0296b2b42c66799 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Wed, 4 Sep 2024 21:12:13 +0200
Subject: [PATCH 1/2] [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)

>From bdfb990e38ada88b943a26b7dd950b6e8a57ec31 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Thu, 5 Sep 2024 14:31:19 +0200
Subject: [PATCH 2/2] fixup! [Instrumentation] Do not attache line number to
 instrumented call debuginfo

---
 llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp   | 1 +
 llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 48d00cfb967126..8b521ef90723a2 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -949,6 +949,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
   DebugLoc EntryLoc;
   if (IsEntryBB) {
     if (auto SP = F.getSubprogram())
+      // Use a compile-generated source-location for all coverage calls.
       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
diff --git a/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll b/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll
index 301446d7bed651..e446e9e16982b4 100644
--- a/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll
+++ b/llvm/test/Instrumentation/SanitizerCoverage/coverage-dbg.ll
@@ -14,9 +14,11 @@
 ; clang++ ../1.cc -O3 -g -S -emit-llvm  -fno-strict-aliasing
 ; and add sanitize_address to @_ZN1A1fEv
 
-; Test that __sanitizer_cov_trace_pc_guard call has !dbg pointing to the opening { of A::f().
+; Test that __sanitizer_cov_trace_pc_guard call has !dbg pointing at a
+; compiler-generated instruction.
+
 ; CHECK: call void @__sanitizer_cov_trace_pc_guard(ptr{{.*}}) #{{.*}}, !dbg [[A:!.*]]
-; CHECK: [[A]] = !DILocation(line: 0, scope: !{{.*}})
+; CHECK: [[A]] = !DILocation(line: 1, scope: !{{.*}})
 
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"



More information about the llvm-commits mailing list