1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s \
2 // RUN: -faligned-allocation -fsized-deallocation -emit-llvm -o - \
3 // RUN: | FileCheck %s
4
5 typedef __SIZE_TYPE__ size_t;
6
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));
9
10 // Ensure that this declaration doesn't cause operator new to lose its
11 // 'noalias' attribute.
12 void *operator new(size_t);
13
14 namespace std {
15 struct nothrow_t {};
16 enum class align_val_t : size_t { __zero = 0,
17 __max = (size_t)-1 };
18 }
19 std::nothrow_t nothrow;
20
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();
26
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();
32
33 // Declare some other placement operators.
34 void *operator new(size_t, void*, bool) throw();
35 void *operator new[](size_t, void*, bool) throw();
36
37
38 // CHECK-LABEL: define void @test_basic(
test_basic()39 extern "C" void test_basic() {
40 // CHECK: call noalias nonnull i8* @_Znwm(i64 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
41 // CHECK: call void @_ZdlPv({{.*}}) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
42 // CHECK: ret void
43 __builtin_operator_delete(__builtin_operator_new(4));
44 }
45 // CHECK: declare nonnull i8* @_Znwm(i64) [[ATTR_NOBUILTIN:#[^ ]*]]
46 // CHECK: declare void @_ZdlPv(i8*) [[ATTR_NOBUILTIN_NOUNWIND:#[^ ]*]]
47
48 // CHECK-LABEL: define void @test_aligned_alloc(
test_aligned_alloc()49 extern "C" void test_aligned_alloc() {
50 // CHECK: call noalias nonnull align 4 i8* @_ZnwmSt11align_val_t(i64 4, i64 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
51 // CHECK: call void @_ZdlPvSt11align_val_t({{.*}}, i64 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
52 __builtin_operator_delete(__builtin_operator_new(4, std::align_val_t(4)), std::align_val_t(4));
53 }
54 // CHECK: declare nonnull i8* @_ZnwmSt11align_val_t(i64, i64) [[ATTR_NOBUILTIN:#[^ ]*]]
55 // CHECK: declare void @_ZdlPvSt11align_val_t(i8*, i64) [[ATTR_NOBUILTIN_NOUNWIND:#[^ ]*]]
56
57 // CHECK-LABEL: define void @test_sized_delete(
test_sized_delete()58 extern "C" void test_sized_delete() {
59 // CHECK: call noalias nonnull i8* @_Znwm(i64 4) [[ATTR_BUILTIN_NEW:#[^ ]*]]
60 // CHECK: call void @_ZdlPvm({{.*}}, i64 4) [[ATTR_BUILTIN_DELETE:#[^ ]*]]
61 __builtin_operator_delete(__builtin_operator_new(4), 4);
62 }
63 // CHECK: declare void @_ZdlPvm(i8*, i64) [[ATTR_NOBUILTIN_UNWIND:#[^ ]*]]
64
65
66 // CHECK-DAG: attributes [[ATTR_NOBUILTIN]] = {{[{].*}} nobuiltin {{.*[}]}}
67 // CHECK-DAG: attributes [[ATTR_NOBUILTIN_NOUNWIND]] = {{[{].*}} nobuiltin nounwind {{.*[}]}}
68
69 // CHECK-DAG: attributes [[ATTR_BUILTIN_NEW]] = {{[{].*}} builtin {{.*[}]}}
70 // CHECK-DAG: attributes [[ATTR_BUILTIN_DELETE]] = {{[{].*}} builtin {{.*[}]}}
71