[FuncAttrs] Don't infer noundef for functions with sanitize_memory attribute#76691
Merged
[FuncAttrs] Don't infer noundef for functions with sanitize_memory attribute#76691
noundef for functions with sanitize_memory attribute#76691Conversation
Member
|
@llvm/pr-subscribers-llvm-transforms Author: Yingwei Zheng (dtcxzyw) ChangesMemorySanitizer assumes that the definition and declaration of a function will be consistent. If we add Fix buildbot failure caused by #76553. Full diff: https://github.com/llvm/llvm-project/pull/76691.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index ce083979afc63a..7ebf265e17ba1f 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1296,6 +1296,12 @@ static void addNoUndefAttrs(const SCCNodeSet &SCCNodes,
if (!F->hasExactDefinition())
return;
+ // MemorySanitizer assumes that the definition and declaration of a
+ // function will be consistent. A function with sanitize_memory attribute
+ // should be skipped from inference.
+ if (F->hasFnAttribute(Attribute::SanitizeMemory))
+ continue;
+
if (F->getReturnType()->isVoidTy())
continue;
diff --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll b/llvm/test/Transforms/FunctionAttrs/noundef.ll
index b357587cc12394..946b562f39553e 100644
--- a/llvm/test/Transforms/FunctionAttrs/noundef.ll
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -143,3 +143,12 @@ define i32 @test_noundef_prop() {
%ret = call i32 @test_ret_constant()
ret i32 %ret
}
+
+; Don't deduce noundef for functions with sanitize_memory.
+define i32 @test_ret_constant_msan() sanitize_memory {
+; CHECK-LABEL: define i32 @test_ret_constant_msan(
+; CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT: ret i32 0
+;
+ ret i32 0
+}
|
nikic
approved these changes
Jan 1, 2024
| @@ -1296,6 +1296,12 @@ static void addNoUndefAttrs(const SCCNodeSet &SCCNodes, | |||
| if (!F->hasExactDefinition()) | |||
| return; | |||
Contributor
There was a problem hiding this comment.
Unrelated to this PR, but I think this should be continue rather than return as well.
Collaborator
|
Thank you! Probably we can skip only not internal/private linkage, but I don't think performance improvement will be meaningful for msan, So as is LGTM for simplicity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MemorySanitizer assumes that the definition and declaration of a function will be consistent. If we add
noundeffor some definitions, it will break msan.Fix buildbot failure caused by #76553.