Skip to content

Commit 7e405eb

Browse files
authored
[FuncAttrs] Don't infer noundef for functions with sanitize_memory attribute (#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.
1 parent 3c99d25 commit 7e405eb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,12 @@ static void addNoUndefAttrs(const SCCNodeSet &SCCNodes,
12961296
if (!F->hasExactDefinition())
12971297
return;
12981298

1299+
// MemorySanitizer assumes that the definition and declaration of a
1300+
// function will be consistent. A function with sanitize_memory attribute
1301+
// should be skipped from inference.
1302+
if (F->hasFnAttribute(Attribute::SanitizeMemory))
1303+
continue;
1304+
12991305
if (F->getReturnType()->isVoidTy())
13001306
continue;
13011307

llvm/test/Transforms/FunctionAttrs/noundef.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,12 @@ define i32 @test_noundef_prop() {
143143
%ret = call i32 @test_ret_constant()
144144
ret i32 %ret
145145
}
146+
147+
; Don't deduce noundef for functions with sanitize_memory.
148+
define i32 @test_ret_constant_msan() sanitize_memory {
149+
; CHECK-LABEL: define i32 @test_ret_constant_msan(
150+
; CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
151+
; CHECK-NEXT: ret i32 0
152+
;
153+
ret i32 0
154+
}

0 commit comments

Comments
 (0)