[llvm] [rtsan] Handle attributed IR function declarations (PR #169577)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 1 01:47:55 PST 2025


https://github.com/davidtrevelyan updated https://github.com/llvm/llvm-project/pull/169577

>From 0ca2359bf675a9220de58e23243acb7222a035af Mon Sep 17 00:00:00 2001
From: David Trevelyan <david.trevelyan at gmail.com>
Date: Tue, 25 Nov 2025 22:23:10 +0000
Subject: [PATCH] [rtsan] Handle attributed IR function declarations

Addresses https://github.com/llvm/llvm-project/issues/169377.

Previously, the RealtimeSanitizer pass only handled attributed function
definitions in IR, and attributed function declarations caused it to
crash. To fix the issue, we must check whether the IR function is empty
before attempting to do any manipulation of its instructions.
---
 .../Transforms/Instrumentation/RealtimeSanitizer.cpp  |  3 +++
 .../RealtimeSanitizer/rtsan_attrib_declare.ll         | 11 +++++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 llvm/test/Instrumentation/RealtimeSanitizer/rtsan_attrib_declare.ll

diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp
index 5ef6ffb58a7c1..667fdb746175f 100644
--- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp
@@ -90,6 +90,9 @@ PreservedAnalyses RealtimeSanitizerPass::run(Module &M,
       [&](Function *Ctor, FunctionCallee) { appendToGlobalCtors(M, Ctor, 0); });
 
   for (Function &F : M) {
+    if (F.empty())
+      continue;
+
     if (F.hasFnAttribute(Attribute::SanitizeRealtime))
       runSanitizeRealtime(F);
 
diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_attrib_declare.ll b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_attrib_declare.ll
new file mode 100644
index 0000000000000..3526a010ce489
--- /dev/null
+++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_attrib_declare.ll
@@ -0,0 +1,11 @@
+; RUN: opt < %s -passes='rtsan' -S | FileCheck %s
+
+declare void @declared_realtime_function() sanitize_realtime #0
+
+declare void @declared_blocking_function() sanitize_realtime_blocking #0
+
+; RealtimeSanitizer pass should ignore attributed functions that are just declarations
+; CHECK: declared_realtime_function
+; CHECK-EMPTY:
+; CHECK: declared_blocking_function
+; CHECK-EMPTY:



More information about the llvm-commits mailing list