-
Notifications
You must be signed in to change notification settings - Fork 15.4k
release/21.x: [rtsan] Handle attributed IR function declarations (#169577) #170641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/21.x
Are you sure you want to change the base?
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 Full diff: https://github.com/llvm/llvm-project/pull/170641.diff 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.
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.
Backport 5d4c441
Requested by: @davidtrevelyan