Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s |
Daniel Dunbar | 010c3f5 | 2009-11-12 00:41:41 +0000 | [diff] [blame] | 2 | #include <stddef.h> |
Anders Carlsson | ed4e367 | 2009-05-31 20:21:44 +0000 | [diff] [blame] | 3 | |
4 | void t1() { | ||||
5 | int* a = new int; | ||||
6 | } | ||||
Anders Carlsson | d958389 | 2009-05-31 20:26:12 +0000 | [diff] [blame] | 7 | |
8 | // Placement. | ||||
Daniel Dunbar | 010c3f5 | 2009-11-12 00:41:41 +0000 | [diff] [blame] | 9 | void* operator new(size_t, void*) throw(); |
Anders Carlsson | d958389 | 2009-05-31 20:26:12 +0000 | [diff] [blame] | 10 | |
11 | void t2(int* a) { | ||||
12 | int* b = new (a) int; | ||||
13 | } | ||||
Anders Carlsson | 6d0ffad | 2009-05-31 20:56:36 +0000 | [diff] [blame] | 14 | |
Anders Carlsson | 627a3e5 | 2009-05-31 21:12:26 +0000 | [diff] [blame] | 15 | struct S { |
16 | int a; | ||||
17 | }; | ||||
18 | |||||
Anders Carlsson | d3fd6ba | 2009-05-31 21:53:59 +0000 | [diff] [blame] | 19 | // POD types. |
Anders Carlsson | 6d0ffad | 2009-05-31 20:56:36 +0000 | [diff] [blame] | 20 | void t3() { |
21 | int *a = new int(10); | ||||
Anders Carlsson | 3923e95 | 2009-05-31 21:07:58 +0000 | [diff] [blame] | 22 | _Complex int* b = new _Complex int(10i); |
23 | |||||
Anders Carlsson | 627a3e5 | 2009-05-31 21:12:26 +0000 | [diff] [blame] | 24 | S s; |
25 | s.a = 10; | ||||
26 | S *sp = new S(s); | ||||
Anders Carlsson | 6d0ffad | 2009-05-31 20:56:36 +0000 | [diff] [blame] | 27 | } |
Anders Carlsson | d3fd6ba | 2009-05-31 21:53:59 +0000 | [diff] [blame] | 28 | |
29 | // Non-POD | ||||
30 | struct T { | ||||
31 | T(); | ||||
32 | int a; | ||||
33 | }; | ||||
34 | |||||
35 | void t4() { | ||||
Anders Carlsson | a4d4c01 | 2009-09-23 16:07:23 +0000 | [diff] [blame] | 36 | // CHECK: call void @_ZN1TC1Ev |
Anders Carlsson | d3fd6ba | 2009-05-31 21:53:59 +0000 | [diff] [blame] | 37 | T *t = new T; |
38 | } | ||||
39 | |||||
40 | struct T2 { | ||||
41 | int a; | ||||
42 | T2(int, int); | ||||
43 | }; | ||||
44 | |||||
45 | void t5() { | ||||
Anders Carlsson | a4d4c01 | 2009-09-23 16:07:23 +0000 | [diff] [blame] | 46 | // CHECK: call void @_ZN2T2C1Eii |
Anders Carlsson | d3fd6ba | 2009-05-31 21:53:59 +0000 | [diff] [blame] | 47 | T2 *t2 = new T2(10, 10); |
48 | } | ||||
Anders Carlsson | f110853 | 2009-06-01 00:05:16 +0000 | [diff] [blame] | 49 | |
50 | int *t6() { | ||||
51 | // Null check. | ||||
52 | return new (0) int(10); | ||||
53 | } | ||||
Anders Carlsson | 215bd20 | 2009-06-01 00:26:14 +0000 | [diff] [blame] | 54 | |
55 | void t7() { | ||||
56 | new int(); | ||||
57 | } | ||||
Anders Carlsson | a4d4c01 | 2009-09-23 16:07:23 +0000 | [diff] [blame] | 58 | |
Anders Carlsson | 6ac5fc4 | 2009-09-23 18:59:48 +0000 | [diff] [blame] | 59 | struct U { |
60 | ~U(); | ||||
61 | }; | ||||
62 | |||||
Anders Carlsson | a4d4c01 | 2009-09-23 16:07:23 +0000 | [diff] [blame] | 63 | void t8(int n) { |
64 | new int[10]; | ||||
65 | new int[n]; | ||||
66 | |||||
67 | // Non-POD | ||||
68 | new T[10]; | ||||
69 | new T[n]; | ||||
Anders Carlsson | 6ac5fc4 | 2009-09-23 18:59:48 +0000 | [diff] [blame] | 70 | |
71 | // Cookie required | ||||
72 | new U[10]; | ||||
73 | new U[n]; | ||||
Anders Carlsson | a4d4c01 | 2009-09-23 16:07:23 +0000 | [diff] [blame] | 74 | } |
Anders Carlsson | 09edb9c | 2009-11-22 19:25:33 +0000 | [diff] [blame] | 75 | |
76 | void t9() { | ||||
77 | bool b; | ||||
78 | |||||
79 | new bool(true); | ||||
80 | new (&b) bool(true); | ||||
81 | } | ||||
Fariborz Jahanian | 048f52a | 2009-11-24 18:29:37 +0000 | [diff] [blame] | 82 | |
83 | struct A { | ||||
84 | void* operator new(__typeof(sizeof(int)), int, float, ...); | ||||
85 | A(); | ||||
86 | }; | ||||
87 | |||||
88 | A* t10() { | ||||
89 | // CHECK: @_ZN1AnwEmifz | ||||
90 | return new(1, 2, 3.45, 100) A; | ||||
91 | } | ||||
92 | |||||
Anders Carlsson | 30311fa | 2009-12-16 06:57:54 +0000 | [diff] [blame] | 93 | struct B { }; |
94 | void t11() { | ||||
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 95 | // CHECK: call noalias i8* @_Znwm |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame^] | 96 | // CHECK: call void @llvm.memset.p0i8.i64( |
Anders Carlsson | 30311fa | 2009-12-16 06:57:54 +0000 | [diff] [blame] | 97 | B* b = new B(); |
98 | } |