https://github.com/a-nogikh created 
https://github.com/llvm/llvm-project/pull/183049

The alloc-token-lower.c test only covered standard (and non-standard) 
malloc-annotated allocation function.

Ensure that the code generation works as intended also for the standard 
malloc_span-annotated functions with the example of __size_returning_new.

>From 47e4ad81b582ce433c546841e8935f9551c4f84e Mon Sep 17 00:00:00 2001
From: Aleksandr Nogikh <[email protected]>
Date: Tue, 24 Feb 2026 12:25:05 +0000
Subject: [PATCH] [AllocToken] Test alloc-token code generation for
 __size_returning_new

The alloc-token-lower.c test only covered standard (and non-standard)
malloc-annotated allocation function.

Ensure that the code generation works as intended also for the standard
malloc_span-annotated functions with the example of
__size_returning_new.
---
 clang/test/CodeGen/alloc-token-lower.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/clang/test/CodeGen/alloc-token-lower.c 
b/clang/test/CodeGen/alloc-token-lower.c
index 2d87b02c6a288..9ab50ca7cd938 100644
--- a/clang/test/CodeGen/alloc-token-lower.c
+++ b/clang/test/CodeGen/alloc-token-lower.c
@@ -36,4 +36,20 @@ void *test_nonlibcall_malloc() {
   return nonstandard_malloc(sizeof(int));
 }
 
+// Ensure that the standard allocation functions annotated with malloc_span
+// are properly instrumented as well.
+typedef struct {
+    void *p;
+    size_t n;
+} __sized_ptr_t;
+__sized_ptr_t __size_returning_new(size_t size) __attribute__((malloc_span));
+
+// CHECK-LABEL: @test_size_returning_new
+// DEFAULT: call{{.*}} { ptr, i64 } @__alloc_token___size_returning_new(i64 
noundef 4, i64 2689373973731826898){{.*}} !alloc_token [[META_INT]]
+// FASTABI: call{{.*}} { ptr, i64 } 
@__alloc_token_2689373973731826898___size_returning_new(i64 noundef 4){{.*}} 
!alloc_token [[META_INT]]
+void *test_size_returning_new() {
+  __sized_ptr_t ret = __size_returning_new(sizeof(int));
+  return ret.p;
+}
+
 // CHECK: [[META_INT]] = !{!"int", i1 false}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to