[llvm-branch-commits] [llvm] release/21.x: [rtsan] Handle attributed IR function declarations (#169577) (PR #170641)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 4 03:04:11 PST 2025
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/170641
Backport 5d4c441
Requested by: @davidtrevelyan
>From b845b4cd771efebf7e09f0016f8c1e75a924a6fb Mon Sep 17 00:00:00 2001
From: davidtrevelyan <davidtrevelyan at users.noreply.github.com>
Date: Mon, 1 Dec 2025 20:56:43 +0000
Subject: [PATCH] [rtsan] Handle attributed IR function declarations (#169577)
Addresses https://github.com/llvm/llvm-project/issues/169377.
Previously, the RealtimeSanitizer pass only handled attributed function
_definitions_ in IR, and we have recently found that 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.
This PR:
- Adds checks for whether IR `Function`s are `empty()` ~~in each
relevant~~ at the top-level RTSan pass routine
- ~~Removes the utility function `rtsanPreservedCFGAnalyses` from the
pass, whose result was unused and which would otherwise have complicated
the fix~~
(cherry picked from commit 5d4c4411f13755d5f12a83a0d6705e8501f33d5f)
---
.../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-branch-commits
mailing list