|
8 | 8 |
|
9 | 9 | #include "llvm/Analysis/TargetLibraryInfo.h" |
10 | 10 | #include "llvm/AsmParser/Parser.h" |
| 11 | +#include "llvm/IR/DerivedTypes.h" |
11 | 12 | #include "llvm/IR/LLVMContext.h" |
12 | 13 | #include "llvm/IR/Module.h" |
13 | 14 | #include "llvm/Support/SourceMgr.h" |
@@ -81,6 +82,30 @@ TEST_F(TargetLibraryInfoTest, InvalidProto) { |
81 | 82 | } |
82 | 83 | } |
83 | 84 |
|
| 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 | + |
84 | 109 | // Check that we do accept know-correct prototypes. |
85 | 110 | TEST_F(TargetLibraryInfoTest, ValidProto) { |
86 | 111 | parseAssembly( |
@@ -472,10 +497,11 @@ TEST_F(TargetLibraryInfoTest, ValidProto) { |
472 | 497 | "declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, %struct*)\n" |
473 | 498 | "declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, " |
474 | 499 | "%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" |
479 | 505 |
|
480 | 506 | "declare void @\"??3@YAXPEAX@Z\"(i8*)\n" |
481 | 507 | "declare void @\"??3@YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n" |
|
0 commit comments