1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s \
2 // RUN: -faligned-allocation -fsized-deallocation -emit-llvm -o - \
5 typedef __SIZE_TYPE__
size_t;
7 // Declare an 'operator new' template to tickle a bug in __builtin_operator_new.
8 template<typename T
> void *operator new(size_t, int (*)(T
));
10 // Ensure that this declaration doesn't cause operator new to lose its
11 // 'noalias' attribute.
12 void *operator new(size_t);
16 enum class align_val_t
: size_t { __zero
= 0,
19 std::nothrow_t nothrow
;
21 // Declare the reserved placement operators.
22 void *operator new(size_t, void*) throw();
23 void operator delete(void*, void*) throw();
24 void *operator new[](size_t, void*) throw();
25 void operator delete[](void*, void*) throw();
27 // Declare the replaceable global allocation operators.
28 void *operator new(size_t, const std::nothrow_t
&) throw();
29 void *operator new[](size_t, const std::nothrow_t
&) throw();
30 void operator delete(void *, const std::nothrow_t
&) throw();
31 void operator delete[](void *, const std::nothrow_t
&) throw();
33 // Declare some other placement operators.
34 void *operator new(size_t, void*, bool) throw();
35 void *operator new[](size_t, void*, bool) throw();
38 // CHECK-LABEL: define{{.*}} void @test_basic(
39 extern "C" void test_basic() {
40 // CHECK: call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
41 // CHECK: call void @_ZdlPv({{.*}}) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
43 __builtin_operator_delete(__builtin_operator_new(4));
45 // CHECK: declare noundef nonnull ptr @_Znwm(i64 noundef) [[ATTR_NOBUILTIN:#[^ ]*]]
46 // CHECK: declare void @_ZdlPv(ptr noundef) [[ATTR_NOBUILTIN_NOUNWIND:#[^ ]*]]
48 // CHECK-LABEL: define{{.*}} void @test_aligned_alloc(
49 extern "C" void test_aligned_alloc() {
50 // CHECK: call noalias noundef nonnull align 4 ptr @_ZnwmSt11align_val_t(i64 noundef 4, i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
51 // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
52 __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
54 // CHECK: declare noundef nonnull ptr @_ZnwmSt11align_val_t(i64 noundef, i64 noundef) [[ATTR_NOBUILTIN:#[^ ]*]]
55 // CHECK: declare void @_ZdlPvSt11align_val_t(ptr noundef, i64 noundef) [[ATTR_NOBUILTIN_NOUNWIND:#[^ ]*]]
57 // CHECK-LABEL: define{{.*}} void @test_sized_delete(
58 extern "C" void test_sized_delete() {
59 // CHECK: call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
60 // CHECK: call void @_ZdlPvm({{.*}}, i64 noundef 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
61 __builtin_operator_delete(__builtin_operator_new(4), 4);
63 // CHECK: declare void @_ZdlPvm(ptr noundef, i64 noundef) [[ATTR_NOBUILTIN_UNWIND:#[^ ]*]]
66 // CHECK-DAG: attributes [[ATTR_NOBUILTIN]] = {{[{].*}} nobuiltin {{.*[}]}}
67 // CHECK-DAG: attributes [[ATTR_NOBUILTIN_NOUNWIND]] = {{[{].*}} nobuiltin nounwind {{.*[}]}}
69 // CHECK-DAG: attributes [[ATTR_BUILTIN_NEW]] = {{[{].*}} builtin {{.*[}]}}
70 // CHECK-DAG: attributes [[ATTR_BUILTIN_DELETE]] = {{[{].*}} builtin {{.*[}]}}