Skip to content

Commit f9cb56f

Browse files
author
Snehasish Kumar
committed
Add a test to check return types for __size_returning_new LibFuncs.
This patch adds a unittest to check that the LibFunc variants have the expected return type of {void*, size_t}. We only check with the 64 bit variant.
1 parent cece4ba commit f9cb56f

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/Analysis/TargetLibraryInfo.h"
1010
#include "llvm/AsmParser/Parser.h"
11+
#include "llvm/IR/DerivedTypes.h"
1112
#include "llvm/IR/LLVMContext.h"
1213
#include "llvm/IR/Module.h"
1314
#include "llvm/Support/SourceMgr.h"
@@ -81,6 +82,30 @@ TEST_F(TargetLibraryInfoTest, InvalidProto) {
8182
}
8283
}
8384

85+
TEST_F(TargetLibraryInfoTest, SizeReturningNewProto) {
86+
parseAssembly("target datalayout = \"p:64:64:64\"\n"
87+
"declare {i8*, i64} @__size_returning_new(i64)\n"
88+
"declare {i8*, i64} @__size_returning_new_hot_cold(i64, i8)\n"
89+
"declare {i8*, i64} @__size_returning_new_aligned(i64, i64)\n"
90+
"declare {i8*, i64} "
91+
"@__size_returning_new_aligned_hot_cold(i64, i64, i8)\n");
92+
93+
llvm::Type *I8Ty = Type::getInt8Ty(Context);
94+
llvm::PointerType *I8PtrTy = PointerType::get(I8Ty, 0);
95+
llvm::StructType *SizedPtrT =
96+
llvm::StructType::get(Context, {I8PtrTy, Type::getInt64Ty(Context)});
97+
98+
for (const LibFunc LF :
99+
{LibFunc_size_returning_new, LibFunc_size_returning_new_aligned,
100+
LibFunc_size_returning_new_hot_cold,
101+
LibFunc_size_returning_new_aligned_hot_cold}) {
102+
TLII.setAvailable(LF);
103+
Function *F = M->getFunction(TLI.getName(LF));
104+
ASSERT_NE(F, nullptr);
105+
EXPECT_EQ(F->getReturnType(), SizedPtrT);
106+
}
107+
}
108+
84109
// Check that we do accept know-correct prototypes.
85110
TEST_F(TargetLibraryInfoTest, ValidProto) {
86111
parseAssembly(
@@ -472,10 +497,11 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
472497
"declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, %struct*)\n"
473498
"declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, "
474499
"%struct*, i8)\n"
475-
"declare %struct @__size_returning_new(i64)\n"
476-
"declare %struct @__size_returning_new_hot_cold(i64, i8)\n"
477-
"declare %struct @__size_returning_new_aligned(i64, i64)\n"
478-
"declare %struct @__size_returning_new_aligned_hot_cold(i64, i64, i8)\n"
500+
"declare {i8*, i64} @__size_returning_new(i64)\n"
501+
"declare {i8*, i64} @__size_returning_new_hot_cold(i64, i8)\n"
502+
"declare {i8*, i64} @__size_returning_new_aligned(i64, i64)\n"
503+
"declare {i8*, i64} @__size_returning_new_aligned_hot_cold(i64, i64, "
504+
"i8)\n"
479505

480506
"declare void @\"??3@YAXPEAX@Z\"(i8*)\n"
481507
"declare void @\"??3@YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n"

0 commit comments

Comments
 (0)