Skip to content

Commit

Permalink
[InferAttrs] If readonly is already set, set readnone instead of writ…
Browse files Browse the repository at this point in the history
…eonly

D116426 may lead to an assertion failure `Attributes 'readonly and writeonly' are incompatible!` if the builtin function already has `readonly`.
  • Loading branch information
MaskRay committed Jan 5, 2022
1 parent c75cedc commit 1eb5b6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ static bool setOnlyReadsMemory(Function &F) {
static bool setDoesNotReadMemory(Function &F) {
if (F.doesNotReadMemory()) // writeonly or readnone
return false;
F.setDoesNotReadMemory();
++NumWriteOnly;
if (F.hasFnAttribute(Attribute::ReadOnly)) {
F.removeFnAttr(Attribute::ReadOnly);
F.setDoesNotAccessMemory();
} else {
F.setDoesNotReadMemory();
}
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Transforms/InferFunctionAttrs/annotate.ll
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ declare i32 @abs(i32)
; CHECK: declare noundef i32 @access(i8* nocapture noundef readonly, i32 noundef) [[NOFREE_NOUNWIND:#[0-9]+]]
declare i32 @access(i8*, i32)

; CHECK: declare double @acos(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare double @acos(double)
; CHECK: declare double @acos(double) [[NOFREE_NOUNWIND_WILLRETURN_READNONE:#[0-9]+]]
declare double @acos(double) readonly

; CHECK: declare float @acosf(float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare float @acosf(float)
Expand Down Expand Up @@ -1065,6 +1065,7 @@ declare void @memset_pattern16(i8*, i8*, i64)

; CHECK-DAG: attributes [[NOFREE_NOUNWIND_WILLRETURN]] = { mustprogress nofree nounwind willreturn }
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]] = { mustprogress nofree nounwind willreturn writeonly }
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_WILLRETURN_READNONE]] = { mustprogress nofree nosync nounwind readnone willreturn }
; CHECK-DAG: attributes [[NOFREE_NOUNWIND]] = { nofree nounwind }
; CHECK-DAG: attributes [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN]] = { inaccessiblememonly mustprogress nofree nounwind willreturn }
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_READONLY_WILLRETURN]] = { mustprogress nofree nounwind readonly willreturn }
Expand Down

0 comments on commit 1eb5b6e

Please sign in to comment.