[TLI] Add support for pvalloc() (#144949)
While pvalloc() is a legacy POSIX function, it remains widely available in common C libraries like glibc. Model pvalloc() in TargetLibraryInfo, allowing LLVM to correctly infer its attributes.
This commit is contained in:
@@ -2046,6 +2046,11 @@ TLI_DEFINE_ENUM_INTERNAL(puts)
|
||||
TLI_DEFINE_STRING_INTERNAL("puts")
|
||||
TLI_DEFINE_SIG_INTERNAL(Int, Ptr)
|
||||
|
||||
/// void *pvalloc(size_t size);
|
||||
TLI_DEFINE_ENUM_INTERNAL(pvalloc)
|
||||
TLI_DEFINE_STRING_INTERNAL("pvalloc")
|
||||
TLI_DEFINE_SIG_INTERNAL(Ptr, SizeT)
|
||||
|
||||
/// ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
|
||||
TLI_DEFINE_ENUM_INTERNAL(pwrite)
|
||||
TLI_DEFINE_STRING_INTERNAL("pwrite")
|
||||
|
||||
@@ -814,6 +814,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
|
||||
TLI.setUnavailable(LibFunc_pclose);
|
||||
TLI.setUnavailable(LibFunc_popen);
|
||||
TLI.setUnavailable(LibFunc_pread);
|
||||
TLI.setUnavailable(LibFunc_pvalloc);
|
||||
TLI.setUnavailable(LibFunc_pwrite);
|
||||
TLI.setUnavailable(LibFunc_read);
|
||||
TLI.setUnavailable(LibFunc_readlink);
|
||||
|
||||
@@ -514,10 +514,12 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
|
||||
case LibFunc_valloc:
|
||||
case LibFunc_malloc:
|
||||
case LibFunc_vec_malloc:
|
||||
Changed |= setAllocSize(F, 0, std::nullopt);
|
||||
[[fallthrough]];
|
||||
case LibFunc_pvalloc:
|
||||
Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
|
||||
: "malloc");
|
||||
Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
|
||||
Changed |= setAllocSize(F, 0, std::nullopt);
|
||||
Changed |= setOnlyAccessesInaccessibleMemory(F);
|
||||
Changed |= setRetAndArgsNoUndef(F);
|
||||
Changed |= setDoesNotThrow(F);
|
||||
|
||||
@@ -812,6 +812,9 @@ declare i32 @putchar_unlocked(i32)
|
||||
; CHECK: declare noundef i32 @puts(ptr noundef readonly captures(none)) [[NOFREE_NOUNWIND]]
|
||||
declare i32 @puts(ptr)
|
||||
|
||||
; CHECK: declare noalias noundef ptr @pvalloc(i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCKIND_ALLOCUNINIT_FAMILY_MALLOC:#[0-9]+]]
|
||||
declare ptr @pvalloc(i64)
|
||||
|
||||
; CHECK: declare noundef i64 @pwrite(i32 noundef, ptr noundef readonly captures(none), i64 noundef, i64 noundef) [[NOFREE]]
|
||||
declare i64 @pwrite(i32, ptr, i64, i64)
|
||||
|
||||
@@ -1195,6 +1198,7 @@ declare void @memset_pattern16(ptr, ptr, i64)
|
||||
; CHECK-DAG: attributes [[NOFREE_NOUNWIND_READONLY]] = { nofree nounwind memory(read) }
|
||||
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCKIND_FREE_FAMILY_MALLOC]] = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
|
||||
; CHECK-DAG: attributes [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCKIND_ALLOCUNINIT_ALLOCSIZE0_FAMILY_MALLOC]] = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
|
||||
; CHECK-DAG: attributes [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCKIND_ALLOCUNINIT_FAMILY_MALLOC]] = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
|
||||
; CHECK-DAG: attributes [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY_WILLRETURN]] = { mustprogress nocallback nofree nounwind willreturn memory(argmem: read) }
|
||||
; CHECK-DAG: attributes [[NOFREE]] = { nofree }
|
||||
; CHECK-DAG: attributes [[ARGMEMONLY_NOFREE_NOUNWIND]] = { nocallback nofree nounwind memory(argmem: readwrite) }
|
||||
|
||||
@@ -54,10 +54,10 @@
|
||||
## the exact count first; the two directives should add up to that.
|
||||
## Yes, this means additions to TLI will fail this test, but the argument
|
||||
## to -COUNT can't be an expression.
|
||||
# AVAIL: TLI knows 523 symbols, 289 available
|
||||
# AVAIL: TLI knows 524 symbols, 289 available
|
||||
# AVAIL-COUNT-289: {{^}} available
|
||||
# AVAIL-NOT: {{^}} available
|
||||
# UNAVAIL-COUNT-234: not available
|
||||
# UNAVAIL-COUNT-235: not available
|
||||
# UNAVAIL-NOT: not available
|
||||
|
||||
## This is a large file so it's worth telling lit to stop here.
|
||||
|
||||
@@ -315,6 +315,7 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
|
||||
"declare i32 @putchar(i32)\n"
|
||||
"declare i32 @putchar_unlocked(i32)\n"
|
||||
"declare i32 @puts(i8*)\n"
|
||||
"declare i8* @pvalloc(i64)\n"
|
||||
"declare void @qsort(i8*, i64, i64, i32 (i8*, i8*)*)\n"
|
||||
"declare i64 @readlink(i8*, i8*, i64)\n"
|
||||
"declare i8* @realloc(i8*, i64)\n"
|
||||
|
||||
Reference in New Issue
Block a user