diff options
author | Snehasish Kumar <snehasishk@google.com> | 2024-08-13 12:44:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-13 12:44:10 -0700 |
commit | 1ccd7ab8b6fa3ae80aaa2e3130242d1d96bbc540 (patch) | |
tree | 03e93e56b4756a665cf74a5f2ab2f27b6534674e /llvm/unittests/Analysis/TargetLibraryInfoTest.cpp | |
parent | ee2359968fa307ef45254c816e14df33374168cd (diff) | |
download | llvm-1ccd7ab8b6fa3ae80aaa2e3130242d1d96bbc540.zip llvm-1ccd7ab8b6fa3ae80aaa2e3130242d1d96bbc540.tar.gz llvm-1ccd7ab8b6fa3ae80aaa2e3130242d1d96bbc540.tar.bz2 |
Enhance TLI detection of __size_returning_new lib funcs. (#102391)
Previously the return types of __size_returning_new variants were not
validated based on their members. This patch checks the members
manually, also generalizes the size_t checks to be based on the module
instead of being hardcoded.
As requested in followup comment on
https://github.com/llvm/llvm-project/pull/101564.
Diffstat (limited to 'llvm/unittests/Analysis/TargetLibraryInfoTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/TargetLibraryInfoTest.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp index d200956..68bf8e6 100644 --- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp +++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp @@ -8,6 +8,7 @@ #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/AsmParser/Parser.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/SourceMgr.h" @@ -81,6 +82,29 @@ TEST_F(TargetLibraryInfoTest, InvalidProto) { } } +TEST_F(TargetLibraryInfoTest, SizeReturningNewInvalidProto) { + parseAssembly( + "target datalayout = \"p:64:64:64\"\n" + ";; Invalid additional params \n" + "declare {i8*, i64} @__size_returning_new(i64, i64)\n" + ";; Invalid params types \n" + "declare {i8*, i64} @__size_returning_new_hot_cold(i64, i32)\n" + ";; Invalid return struct types \n" + "declare {i8*, i8} @__size_returning_new_aligned(i64, i64)\n" + ";; Invalid return type \n" + "declare i8* @__size_returning_new_aligned_hot_cold(i64, i64, i8)\n"); + + for (const LibFunc LF : + {LibFunc_size_returning_new, LibFunc_size_returning_new_aligned, + LibFunc_size_returning_new_hot_cold, + LibFunc_size_returning_new_aligned_hot_cold}) { + TLII.setAvailable(LF); + Function *F = M->getFunction(TLI.getName(LF)); + ASSERT_NE(F, nullptr); + EXPECT_FALSE(isLibFunc(F, LF)); + } +} + // Check that we do accept know-correct prototypes. TEST_F(TargetLibraryInfoTest, ValidProto) { parseAssembly( @@ -472,10 +496,11 @@ TEST_F(TargetLibraryInfoTest, ValidProto) { "declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, %struct*)\n" "declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, " "%struct*, i8)\n" - "declare %struct @__size_returning_new(i64)\n" - "declare %struct @__size_returning_new_hot_cold(i64, i8)\n" - "declare %struct @__size_returning_new_aligned(i64, i64)\n" - "declare %struct @__size_returning_new_aligned_hot_cold(i64, i64, i8)\n" + "declare {i8*, i64} @__size_returning_new(i64)\n" + "declare {i8*, i64} @__size_returning_new_hot_cold(i64, i8)\n" + "declare {i8*, i64} @__size_returning_new_aligned(i64, i64)\n" + "declare {i8*, i64} @__size_returning_new_aligned_hot_cold(i64, i64, " + "i8)\n" "declare void @\"??3@YAXPEAX@Z\"(i8*)\n" "declare void @\"??3@YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n" |