[llvm] [llvm][nsan] Skip function declarations (PR #105598)

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 17:08:19 PDT 2024


https://github.com/alexander-shaposhnikov created https://github.com/llvm/llvm-project/pull/105598

Skip function declarations in the instrumentation pass.


>From 06c6f69d24515e527a0de2df82e011ad5efe73ab Mon Sep 17 00:00:00 2001
From: Alexander Shaposhnikov <ashaposhnikov at google.com>
Date: Thu, 22 Aug 2024 00:06:48 +0000
Subject: [PATCH] [llvm][nsan] Skip function declarations

---
 .../Transforms/Instrumentation/NumericalStabilitySanitizer.cpp | 3 ++-
 llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
index 5872396669435a..ffd9faff1d3a53 100644
--- a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
@@ -2038,7 +2038,8 @@ static void moveFastMathFlags(Function &F,
 
 bool NumericalStabilitySanitizer::sanitizeFunction(
     Function &F, const TargetLibraryInfo &TLI) {
-  if (!F.hasFnAttribute(Attribute::SanitizeNumericalStability))
+  if (!F.hasFnAttribute(Attribute::SanitizeNumericalStability) ||
+      F.isDeclaration())
     return false;
 
   // This is required to prevent instrumenting call to __nsan_init from within
diff --git a/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll b/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
index 5da68320d91f90..2131162bf4bf3f 100644
--- a/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
+++ b/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
@@ -4,6 +4,8 @@
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 
+declare float @declaration_only(float %a) sanitize_numerical_stability
+
 ; Tests with simple control flow.
 
 @float_const = private unnamed_addr constant float 0.5



More information about the llvm-commits mailing list