[llvm] Add a test to check return types for __size_returning_new LibFuncs. (PR #102391)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 7 15:02:19 PDT 2024
https://github.com/snehasish created https://github.com/llvm/llvm-project/pull/102391
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. As requested in followup comment on https://github.com/llvm/llvm-project/pull/101564.
>From f9cb56f629acd634424d598c774654046442288e Mon Sep 17 00:00:00 2001
From: Snehasish Kumar <snehasishk at google.com>
Date: Wed, 7 Aug 2024 21:50:51 +0000
Subject: [PATCH] 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.
---
.../Analysis/TargetLibraryInfoTest.cpp | 34 ++++++++++++++++---
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
index d200956f74102..690b4122b2968 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,30 @@ TEST_F(TargetLibraryInfoTest, InvalidProto) {
}
}
+TEST_F(TargetLibraryInfoTest, SizeReturningNewProto) {
+ parseAssembly("target datalayout = \"p:64:64:64\"\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");
+
+ llvm::Type *I8Ty = Type::getInt8Ty(Context);
+ llvm::PointerType *I8PtrTy = PointerType::get(I8Ty, 0);
+ llvm::StructType *SizedPtrT =
+ llvm::StructType::get(Context, {I8PtrTy, Type::getInt64Ty(Context)});
+
+ 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_EQ(F->getReturnType(), SizedPtrT);
+ }
+}
+
// Check that we do accept know-correct prototypes.
TEST_F(TargetLibraryInfoTest, ValidProto) {
parseAssembly(
@@ -472,10 +497,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 at YAXPEAX@Z\"(i8*)\n"
"declare void @\"??3 at YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n"
More information about the llvm-commits
mailing list