Skip to content

Commit

Permalink
[FuncAttrs] Don't infer noundef for functions with `sanitize_memory…
Browse files Browse the repository at this point in the history
…` 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.
  • Loading branch information
dtcxzyw authored Jan 1, 2024
1 parent 3c99d25 commit 7e405eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions llvm/test/Transforms/FunctionAttrs/noundef.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7e405eb

Please sign in to comment.