release/21.x: [rtsan] Handle attributed IR function declarations (#169577)#170641
release/21.x: [rtsan] Handle attributed IR function declarations (#169577)#170641dyung merged 1 commit intollvm:release/21.xfrom
Conversation
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)
|
@cjappl What do you think about merging this PR to the release branch? |
|
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-compiler-rt-sanitizer Author: None (llvmbot) ChangesBackport 5d4c441 Requested by: @davidtrevelyan 2 Files Affected:
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:
|
|
|
|
Tagging @inkreasing for visibility |
cjappl
left a comment
There was a problem hiding this comment.
LGTM. Definitely a bug we want fixed for Rust as soon as feasible.
Seems low risk for regression.
|
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. |
|
@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. |
Backport 5d4c441
Requested by: @davidtrevelyan