Skip to content

Commit 1eb5b6e

Browse files
committed
[InferAttrs] If readonly is already set, set readnone instead of writeonly
D116426 may lead to an assertion failure `Attributes 'readonly and writeonly' are incompatible!` if the builtin function already has `readonly`.
1 parent c75cedc commit 1eb5b6e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ static bool setOnlyReadsMemory(Function &F) {
7575
static bool setDoesNotReadMemory(Function &F) {
7676
if (F.doesNotReadMemory()) // writeonly or readnone
7777
return false;
78-
F.setDoesNotReadMemory();
7978
++NumWriteOnly;
79+
if (F.hasFnAttribute(Attribute::ReadOnly)) {
80+
F.removeFnAttr(Attribute::ReadOnly);
81+
F.setDoesNotAccessMemory();
82+
} else {
83+
F.setDoesNotReadMemory();
84+
}
8085
return true;
8186
}
8287

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ declare i32 @abs(i32)
201201
; CHECK: declare noundef i32 @access(i8* nocapture noundef readonly, i32 noundef) [[NOFREE_NOUNWIND:#[0-9]+]]
202202
declare i32 @access(i8*, i32)
203203

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

207207
; CHECK: declare float @acosf(float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
208208
declare float @acosf(float)
@@ -1065,6 +1065,7 @@ declare void @memset_pattern16(i8*, i8*, i64)
10651065

10661066
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_WILLRETURN]] = { mustprogress nofree nounwind willreturn }
10671067
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]] = { mustprogress nofree nounwind willreturn writeonly }
1068+
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_WILLRETURN_READNONE]] = { mustprogress nofree nosync nounwind readnone willreturn }
10681069
; CHECK-DAG: attributes [[NOFREE_NOUNWIND]] = { nofree nounwind }
10691070
; CHECK-DAG: attributes [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN]] = { inaccessiblememonly mustprogress nofree nounwind willreturn }
10701071
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_READONLY_WILLRETURN]] = { mustprogress nofree nounwind readonly willreturn }

0 commit comments

Comments
 (0)