Skip to content

release/21.x: [rtsan] Handle attributed IR function declarations (#169577)#170641

Merged
dyung merged 1 commit intollvm:release/21.xfrom
llvmbot:issue169577
Dec 10, 2025
Merged

release/21.x: [rtsan] Handle attributed IR function declarations (#169577)#170641
dyung merged 1 commit intollvm:release/21.xfrom
llvmbot:issue169577

Conversation

@llvmbot
Copy link
Copy Markdown
Member

@llvmbot llvmbot commented Dec 4, 2025

Backport 5d4c441

Requested by: @davidtrevelyan

Addresses llvm#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 5d4c441)
@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Dec 4, 2025

@cjappl What do you think about merging this PR to the release branch?

@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Dec 4, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (llvmbot)

Changes

Backport 5d4c441

Requested by: @davidtrevelyan


Full diff: https://github.com/llvm/llvm-project/pull/170641.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp (+3)
  • (added) llvm/test/Instrumentation/RealtimeSanitizer/rtsan_attrib_declare.ll (+11)
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:

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 4, 2025

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Developer Policy and LLVM Discourse for more information.

@davidtrevelyan
Copy link
Copy Markdown
Contributor

Tagging @inkreasing for visibility

Copy link
Copy Markdown
Contributor

@cjappl cjappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Definitely a bug we want fixed for Rust as soon as feasible.

Seems low risk for regression.

@dyung dyung moved this from Needs Triage to Needs Merge in LLVM Release Status Dec 9, 2025
@dyung
Copy link
Copy Markdown
Collaborator

dyung commented Dec 10, 2025

I will be merging this change in soon, but we also just wanted to let everyone know that this will be the last release of the 21.x branch, so if there are any issues that arise, we will not be able to fix them.

@dyung dyung merged commit b845b4c into llvm:release/21.x Dec 10, 2025
16 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Merge to Done in LLVM Release Status Dec 10, 2025
@github-actions
Copy link
Copy Markdown

@davidtrevelyan (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants