[llvm] Add a test to check return types for __size_returning_new LibFuncs. (PR #102391)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 15:02:51 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Snehasish Kumar (snehasish)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/102391.diff


1 Files Affected:

- (modified) llvm/unittests/Analysis/TargetLibraryInfoTest.cpp (+30-4) 


``````````diff
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"

``````````

</details>


https://github.com/llvm/llvm-project/pull/102391


More information about the llvm-commits mailing list