[llvm] [TySan] Skip instrumentation for function declarations (PR #122488)

Mingjie Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 08:24:11 PST 2025


https://github.com/Enna1 created https://github.com/llvm/llvm-project/pull/122488

Skip function declarations for instrumentation.

>From ddba8f3113058154feb79fc075b2b9a2011f348c Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" <xumingjie.enna1 at bytedance.com>
Date: Sat, 11 Jan 2025 00:13:44 +0800
Subject: [PATCH] [TySan] Skip instrumentation for function declarations

Skip function declarations for instrumentation.
---
 llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp | 2 ++
 llvm/test/Instrumentation/TypeSanitizer/basic.ll      | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
index 9cd81f3e6edb30..2ae8106218667b 100644
--- a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
@@ -512,6 +512,8 @@ void collectMemAccessInfo(
 
 bool TypeSanitizer::sanitizeFunction(Function &F,
                                      const TargetLibraryInfo &TLI) {
+  if (F.isDeclaration())
+    return false;
   // This is required to prevent instrumenting call to __tysan_init from within
   // the module constructor.
   if (&F == TysanCtorFunction.getCallee() || &F == TysanGlobalsSetTypeFunction)
diff --git a/llvm/test/Instrumentation/TypeSanitizer/basic.ll b/llvm/test/Instrumentation/TypeSanitizer/basic.ll
index 704c18800f19e0..b40b64664502a0 100644
--- a/llvm/test/Instrumentation/TypeSanitizer/basic.ll
+++ b/llvm/test/Instrumentation/TypeSanitizer/basic.ll
@@ -5,6 +5,8 @@
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
+declare i32 @declaration_only(i32 %a) sanitize_type
+
 ;.
 ; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @tysan.module_ctor, ptr null }]
 ; CHECK: @__tysan_v1_Simple_20C_2b_2b_20TBAA = linkonce_odr constant { i64, i64, [16 x i8] } { i64 2, i64 0, [16 x i8] c"Simple C++ TBAA\00" }, comdat



More information about the llvm-commits mailing list