Skip to content

Commit 155ac33

Browse files
[BuildLibCalls] Add noalias for strcat and stpcpy
strcat: destination and source shall not overlap. (http://www.cplusplus.com/reference/cstring/strcat/) stpcpy: The strings may not overlap, and the destination string dest must be large enough to receive the copy. (https://man7.org/linux/man-pages/man3/stpcpy.3.html) Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D88335
1 parent 0103df7 commit 155ac33

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
203203
return Changed;
204204
case LibFunc_strcpy:
205205
case LibFunc_strncpy:
206-
Changed |= setDoesNotAlias(F, 0);
207-
Changed |= setDoesNotAlias(F, 1);
208-
LLVM_FALLTHROUGH;
209206
case LibFunc_strcat:
210207
case LibFunc_strncat:
211208
Changed |= setReturnedArg(F, 0);
@@ -215,6 +212,8 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
215212
Changed |= setDoesNotThrow(F);
216213
Changed |= setDoesNotCapture(F, 1);
217214
Changed |= setOnlyReadsMemory(F, 1);
215+
Changed |= setDoesNotAlias(F, 0);
216+
Changed |= setDoesNotAlias(F, 1);
218217
return Changed;
219218
case LibFunc_strxfrm:
220219
Changed |= setDoesNotThrow(F);

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,16 +825,16 @@ declare i32 @statvfs(i8*, %opaque*)
825825
; CHECK-LINUX: declare noundef i32 @statvfs64(i8* nocapture noundef readonly, %opaque* nocapture noundef) [[G1]]
826826
declare i32 @statvfs64(i8*, %opaque*)
827827

828-
; CHECK: declare i8* @stpcpy(i8*, i8* nocapture readonly) [[G1]]
828+
; CHECK: declare i8* @stpcpy(i8* noalias, i8* noalias nocapture readonly) [[G1]]
829829
declare i8* @stpcpy(i8*, i8*)
830830

831-
; CHECK: declare i8* @stpncpy(i8*, i8* nocapture readonly, i64) [[G1]]
831+
; CHECK: declare i8* @stpncpy(i8* noalias, i8* noalias nocapture readonly, i64) [[G1]]
832832
declare i8* @stpncpy(i8*, i8*, i64)
833833

834834
; CHECK: declare i32 @strcasecmp(i8* nocapture, i8* nocapture) [[G2]]
835835
declare i32 @strcasecmp(i8*, i8*)
836836

837-
; CHECK: declare i8* @strcat(i8* returned, i8* nocapture readonly) [[G1]]
837+
; CHECK: declare i8* @strcat(i8* noalias returned, i8* noalias nocapture readonly) [[G1]]
838838
declare i8* @strcat(i8*, i8*)
839839

840840
; CHECK: declare i8* @strchr(i8*, i32) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]]
@@ -861,7 +861,7 @@ declare i64 @strlen(i8*)
861861
; CHECK: declare i32 @strncasecmp(i8* nocapture, i8* nocapture, i64) [[G2]]
862862
declare i32 @strncasecmp(i8*, i8*, i64)
863863

864-
; CHECK: declare i8* @strncat(i8* returned, i8* nocapture readonly, i64) [[G1]]
864+
; CHECK: declare i8* @strncat(i8* noalias returned, i8* noalias nocapture readonly, i64) [[G1]]
865865
declare i8* @strncat(i8*, i8*, i64)
866866

867867
; CHECK: declare i32 @strncmp(i8* nocapture, i8* nocapture, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]]

0 commit comments

Comments
 (0)