[llvm] [FuncAttrs] Don't infer `noundef` for functions with `sanitize_memory` attribute (PR #76691)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 1 14:14:31 PST 2024
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/76691
MemorySanitizer assumes that the definition and declaration of a function will be consistent. If we add `noundef` for some definitions, it will break msan.
Fix buildbot failure caused by #76553.
>From 85a0cbee6ec089261a0e7e8031ce72e160bb7f80 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 2 Jan 2024 06:03:27 +0800
Subject: [PATCH 1/2] [FuncAttrs] Add pre-commit tests. NFC.
---
llvm/test/Transforms/FunctionAttrs/noundef.ll | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/llvm/test/Transforms/FunctionAttrs/noundef.ll b/llvm/test/Transforms/FunctionAttrs/noundef.ll
index b357587cc12394..e36064c3abc957 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
}
+
+; FIXME: Don't deduce noundef for functions with sanitize_memory.
+define i32 @test_ret_constant_msan() sanitize_memory {
+; CHECK-LABEL: define noundef i32 @test_ret_constant_msan(
+; CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT: ret i32 0
+;
+ ret i32 0
+}
>From d295b472726f37e07a1679f8a7f5787e9ea6ce40 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Tue, 2 Jan 2024 06:05:11 +0800
Subject: [PATCH 2/2] [FuncAttrs] Don't infer `noundef` for functions with
`sanitize_memory` attribute
---
llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 6 ++++++
llvm/test/Transforms/FunctionAttrs/noundef.ll | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)
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 e36064c3abc957..946b562f39553e 100644
--- a/llvm/test/Transforms/FunctionAttrs/noundef.ll
+++ b/llvm/test/Transforms/FunctionAttrs/noundef.ll
@@ -144,9 +144,9 @@ define i32 @test_noundef_prop() {
ret i32 %ret
}
-; FIXME: Don't deduce noundef for functions with sanitize_memory.
+; Don't deduce noundef for functions with sanitize_memory.
define i32 @test_ret_constant_msan() sanitize_memory {
-; CHECK-LABEL: define noundef i32 @test_ret_constant_msan(
+; CHECK-LABEL: define i32 @test_ret_constant_msan(
; CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
; CHECK-NEXT: ret i32 0
;
More information about the llvm-commits
mailing list