[llvm] Enhance TLI detection of __size_returning_new lib funcs. (PR #102391)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 00:51:29 PDT 2024


================
@@ -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);
+  }
----------------
nikic wrote:

Can you please also add some negative tests with incorrect signature?

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


More information about the llvm-commits mailing list