new.cpp revision 806941eab5e1d62d7676e5cdc0e1d9e397ea78b4
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s 2#include <stddef.h> 3 4void t1() { 5 int* a = new int; 6} 7 8// Placement. 9void* operator new(size_t, void*) throw(); 10 11void t2(int* a) { 12 int* b = new (a) int; 13} 14 15struct S { 16 int a; 17}; 18 19// POD types. 20void t3() { 21 int *a = new int(10); 22 _Complex int* b = new _Complex int(10i); 23 24 S s; 25 s.a = 10; 26 S *sp = new S(s); 27} 28 29// Non-POD 30struct T { 31 T(); 32 int a; 33}; 34 35void t4() { 36 // CHECK: call void @_ZN1TC1Ev 37 T *t = new T; 38} 39 40struct T2 { 41 int a; 42 T2(int, int); 43}; 44 45void t5() { 46 // CHECK: call void @_ZN2T2C1Eii 47 T2 *t2 = new T2(10, 10); 48} 49 50int *t6() { 51 // Null check. 52 return new (0) int(10); 53} 54 55void t7() { 56 new int(); 57} 58 59struct U { 60 ~U(); 61}; 62 63void t8(int n) { 64 new int[10]; 65 new int[n]; 66 67 // Non-POD 68 new T[10]; 69 new T[n]; 70 71 // Cookie required 72 new U[10]; 73 new U[n]; 74} 75 76void t9() { 77 bool b; 78 79 new bool(true); 80 new (&b) bool(true); 81} 82 83struct A { 84 void* operator new(__typeof(sizeof(int)), int, float, ...); 85 A(); 86}; 87 88A* t10() { 89 // CHECK: @_ZN1AnwEmifz 90 return new(1, 2, 3.45, 100) A; 91} 92 93struct B { int a; }; 94void t11() { 95 // CHECK: call noalias i8* @_Znwm 96 // CHECK: call void @llvm.memset.p0i8.i64( 97 B* b = new B(); 98} 99 100struct Empty { }; 101 102// We don't need to initialize an empty class. 103void t12() { 104 // CHECK: define void @_Z3t12v 105 // CHECK-NOT: br label 106 // CHECK: ret void 107 (void)new Empty[10]; 108} 109