Skip to content

Commit 6b91b33

Browse files
committed
[AllocToken] Test alloc token instrumentation for size-returning functions
The allocation token functionality relies on the instrumentation of the allocation functions, which added a new use case for the "malloc" and "size_alloc" attributes. With the new "malloc_span" attribute for annotating functions returning structs that wrap the pointer to the allocated data, this commit adjusts the allocation token test to ensure that __size_returning_new variants are correctly handled by the alloc token instrumentation.
1 parent f7c3e7b commit 6b91b33

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

clang/test/CodeGenCXX/alloc-token.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ struct __sized_ptr_t {
1717
size_t n;
1818
};
1919
enum class __hot_cold_t : uint8_t;
20-
__sized_ptr_t __size_returning_new(size_t size);
21-
__sized_ptr_t __size_returning_new_hot_cold(size_t, __hot_cold_t);
20+
__sized_ptr_t __size_returning_new(size_t size) __attribute__((malloc_span));
21+
__sized_ptr_t __size_returning_new_hot_cold(size_t, __hot_cold_t) __attribute__((malloc_span));
2222
__sized_ptr_t __size_returning_new_aligned(size_t, std::align_val_t);
23-
__sized_ptr_t __size_returning_new_aligned_hot_cold(size_t, std::align_val_t, __hot_cold_t);
23+
__sized_ptr_t __size_returning_new_aligned_hot_cold(size_t, std::align_val_t, __hot_cold_t) __attribute__((malloc));
2424
}
2525

2626
void *sink; // prevent optimizations from removing the calls
@@ -101,12 +101,12 @@ int *test_new_array_nothrow() {
101101
}
102102

103103
// CHECK-LABEL: define dso_local void @_Z23test_size_returning_newv(
104-
// CHECK: call { ptr, i64 } @__size_returning_new(i64 noundef 8)
105-
// CHECK: call { ptr, i64 } @__size_returning_new_hot_cold(i64 noundef 8, i8 noundef zeroext 1)
104+
// CHECK: call { ptr, i64 } @__size_returning_new(i64 noundef 8){{.*}} !alloc_token [[META_LONG]]
105+
// CHECK: call { ptr, i64 } @__size_returning_new_hot_cold(i64 noundef 8, i8 noundef zeroext 1){{.*}} !alloc_token [[META_LONG]]
106106
// CHECK: call { ptr, i64 } @__size_returning_new_aligned(i64 noundef 8, i64 noundef 32)
107-
// CHECK: call { ptr, i64 } @__size_returning_new_aligned_hot_cold(i64 noundef 8, i64 noundef 32, i8 noundef zeroext 1)
107+
// CHECK: call { ptr, i64 } @__size_returning_new_aligned_hot_cold(i64 noundef 8, i64 noundef 32, i8 noundef zeroext 1){{.*}}_token [[META_LONG]]
108108
void test_size_returning_new() {
109-
// FIXME: Support __size_returning_new variants.
109+
// FIXME: Support __size_returning_new_aligned.
110110
sink = __size_returning_new(sizeof(long)).p;
111111
sink = __size_returning_new_hot_cold(sizeof(long), __hot_cold_t{1}).p;
112112
sink = __size_returning_new_aligned(sizeof(long), std::align_val_t{32}).p;

0 commit comments

Comments
 (0)