Skip to content

Commit 4c32862

Browse files
fixup! [TLI] Add support for reallocarray
1 parent a1ca0d1 commit 4c32862

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,13 +3224,6 @@ def AllocA : GNULibBuiltin<"stdlib.h"> {
32243224
let AddBuiltinPrefixedAlias = 1;
32253225
}
32263226

3227-
// Available in glibc by default since since 2.29 and in GNU mode before.
3228-
def ReallocArray : GNULibBuiltin<"stdlib.h"> {
3229-
let Spellings = ["reallocarray"];
3230-
let Prototype = "void*(void*, size_t, size_t)";
3231-
}
3232-
3233-
32343227
// POSIX malloc.h
32353228

32363229
def MemAlign : GNULibBuiltin<"malloc.h"> {

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
581581
Changed |= setAllocFamily(F, "malloc");
582582
Changed |= setAllocKind(F, AllocFnKind::Realloc);
583583
Changed |= setAllocatedPointerParam(F, 0);
584-
Changed |= setAllocSize(F, 1, std::nullopt);
585-
Changed |= setAllocSize(F, 2, std::nullopt);
584+
Changed |= setAllocSize(F, 1, 2);
586585
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
587586
Changed |= setRetNoUndef(F);
588587
Changed |= setDoesNotThrow(F);

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,9 @@ declare i64 @readlink(ptr, ptr, i64)
827827
; CHECK: declare noalias noundef ptr @realloc(ptr allocptr nocapture, i64 noundef) [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCKIND_REALLOC_ALLOCSIZE1_FAMILY_MALLOC:#[0-9]+]]
828828
declare ptr @realloc(ptr, i64)
829829

830+
; CHECK: declare noalias noundef ptr @reallocarray(ptr allocptr nocapture, i64 noundef, i64 noundef) [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCKIND_REALLOC_ALLOCSIZE12_FAMILY_MALLOC:#[0-9]+]]
831+
declare ptr @reallocarray(ptr, i64, i64)
832+
830833
; CHECK: declare noalias noundef ptr @reallocf(ptr allocptr nocapture, i64 noundef) [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCKIND_REALLOC_ALLOCSIZE1_FAMILY_MALLOC]]
831834
declare ptr @reallocf(ptr, i64)
832835

@@ -1194,6 +1197,7 @@ declare void @memset_pattern16(ptr, ptr, i64)
11941197
; CHECK-DAG: attributes [[NOFREE]] = { nofree }
11951198
; CHECK-DAG: attributes [[ARGMEMONLY_NOFREE_NOUNWIND]] = { nofree nounwind memory(argmem: readwrite) }
11961199
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCKIND_REALLOC_ALLOCSIZE1_FAMILY_MALLOC]] = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
1200+
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCKIND_REALLOC_ALLOCSIZE12_FAMILY_MALLOC]] = { mustprogress nounwind willreturn allockind("realloc") allocsize(1,2) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
11971201
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND_WILLRETURN_FAMILY_MALLOC]] = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
11981202
; CHECK-DAG: attributes [[NOFREE_COLD]] = { cold nofree }
11991203
; CHECK-DAG: attributes [[NOFREE_COLD_NORETURN]] = { cold nofree noreturn }

0 commit comments

Comments
 (0)