[PATCH] D132406: [LibCalls] Mark puts/printf/perror as inaccessible_mem_or_argmem.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 22 12:09:04 PDT 2022
fhahn created this revision.
fhahn added reviewers: jdoerfert, ab, efriedma, t.p.northover.
Herald added a subscriber: hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: LLVM.
Unless I am missing something, those functions should only access
either memory accessible through their arguments or inaccessible memory.
If I am not missing anything, it would probably be worth to add that
attribute to most libcalls.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132406
Files:
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/test/Transforms/InferFunctionAttrs/annotate.ll
Index: llvm/test/Transforms/InferFunctionAttrs/annotate.ll
===================================================================
--- llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -739,8 +739,7 @@
; CHECK: declare noundef i32 @pclose(%opaque* nocapture noundef) [[NOFREE_NOUNWIND]]
declare i32 @pclose(%opaque*)
-
-; CHECK: declare void @perror(i8* nocapture noundef readonly) [[NOFREE_NOUNWIND]]
+; CHECK: declare void @perror(i8* nocapture noundef readonly) [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND:#[0-9]+]]
declare void @perror(i8*)
; CHECK: declare noalias noundef %opaque* @popen(i8* nocapture noundef readonly, i8* nocapture noundef readonly) [[NOFREE_NOUNWIND]]
@@ -761,7 +760,7 @@
; CHECK: declare noundef i64 @pread(i32 noundef, i8* nocapture noundef, i64 noundef, i64 noundef) [[NOFREE]]
declare i64 @pread(i32, i8*, i64, i64)
-; CHECK: declare noundef i32 @printf(i8* nocapture noundef readonly, ...) [[NOFREE_NOUNWIND]]
+; CHECK: declare noundef i32 @printf(i8* nocapture noundef readonly, ...) [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND]]
declare i32 @printf(i8*, ...)
; CHECK: declare noundef i32 @putc(i32 noundef, %opaque* nocapture noundef) [[NOFREE_NOUNWIND]]
@@ -774,7 +773,7 @@
; CHECK-UNKNOWN: declare i32 @putchar_unlocked(i32){{$}}
declare i32 @putchar_unlocked(i32)
-; CHECK: declare noundef i32 @puts(i8* nocapture noundef readonly) [[NOFREE_NOUNWIND]]
+; CHECK: declare noundef i32 @puts(i8* nocapture noundef readonly) [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND]]
declare i32 @puts(i8*)
; CHECK: declare noundef i64 @pwrite(i32 noundef, i8* nocapture noundef readonly, i64 noundef, i64 noundef) [[NOFREE]]
@@ -1096,6 +1095,7 @@
; CHECK-DAG: attributes [[ARGMEMONLY_NOFREE_NOUNWIND]] = { argmemonly nofree nounwind }
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCKIND_REALLOC_ALLOCSIZE1_FAMILY_MALLOC]] = { inaccessiblemem_or_argmemonly mustprogress nounwind willreturn allockind("realloc") allocsize(1) "alloc-family"="malloc" }
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND_WILLRETURN_FAMILY_MALLOC]] = { inaccessiblemem_or_argmemonly mustprogress nofree nounwind willreturn "alloc-family"="malloc" }
+; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND]] = { inaccessiblemem_or_argmemonly nofree nounwind }
; CHECK-NVPTX-DAG: attributes [[NOFREE_NOUNWIND_READNONE]] = { nofree nosync nounwind readnone }
Index: llvm/lib/Transforms/Utils/BuildLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -860,6 +860,7 @@
Changed |= setRetAndArgsNoUndef(F);
Changed |= setDoesNotThrow(F);
Changed |= setDoesNotCapture(F, 0);
+ Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
Changed |= setOnlyReadsMemory(F, 0);
break;
case LibFunc_pread:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132406.454591.patch
Type: text/x-patch
Size: 2988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220822/d7351699/attachment.bin>
More information about the llvm-commits
mailing list