2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s
|
2009-11-12 08:41:41 +08:00
|
|
|
#include <stddef.h>
|
2009-06-01 04:21:44 +08:00
|
|
|
|
|
|
|
void t1() {
|
|
|
|
int* a = new int;
|
|
|
|
}
|
2009-06-01 04:26:12 +08:00
|
|
|
|
|
|
|
// Placement.
|
2009-11-12 08:41:41 +08:00
|
|
|
void* operator new(size_t, void*) throw();
|
2009-06-01 04:26:12 +08:00
|
|
|
|
|
|
|
void t2(int* a) {
|
|
|
|
int* b = new (a) int;
|
|
|
|
}
|
2009-06-01 04:56:36 +08:00
|
|
|
|
2009-06-01 05:12:26 +08:00
|
|
|
struct S {
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
|
2009-06-01 05:53:59 +08:00
|
|
|
// POD types.
|
2009-06-01 04:56:36 +08:00
|
|
|
void t3() {
|
|
|
|
int *a = new int(10);
|
2009-06-01 05:07:58 +08:00
|
|
|
_Complex int* b = new _Complex int(10i);
|
|
|
|
|
2009-06-01 05:12:26 +08:00
|
|
|
S s;
|
|
|
|
s.a = 10;
|
|
|
|
S *sp = new S(s);
|
2009-06-01 04:56:36 +08:00
|
|
|
}
|
2009-06-01 05:53:59 +08:00
|
|
|
|
|
|
|
// Non-POD
|
|
|
|
struct T {
|
|
|
|
T();
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
|
|
|
|
void t4() {
|
2009-09-24 00:07:23 +08:00
|
|
|
// CHECK: call void @_ZN1TC1Ev
|
2009-06-01 05:53:59 +08:00
|
|
|
T *t = new T;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct T2 {
|
|
|
|
int a;
|
|
|
|
T2(int, int);
|
|
|
|
};
|
|
|
|
|
|
|
|
void t5() {
|
2009-09-24 00:07:23 +08:00
|
|
|
// CHECK: call void @_ZN2T2C1Eii
|
2009-06-01 05:53:59 +08:00
|
|
|
T2 *t2 = new T2(10, 10);
|
|
|
|
}
|
2009-06-01 08:05:16 +08:00
|
|
|
|
|
|
|
int *t6() {
|
|
|
|
// Null check.
|
|
|
|
return new (0) int(10);
|
|
|
|
}
|
2009-06-01 08:26:14 +08:00
|
|
|
|
|
|
|
void t7() {
|
|
|
|
new int();
|
|
|
|
}
|
2009-09-24 00:07:23 +08:00
|
|
|
|
2009-09-24 02:59:48 +08:00
|
|
|
struct U {
|
|
|
|
~U();
|
|
|
|
};
|
|
|
|
|
2009-09-24 00:07:23 +08:00
|
|
|
void t8(int n) {
|
|
|
|
new int[10];
|
|
|
|
new int[n];
|
|
|
|
|
|
|
|
// Non-POD
|
|
|
|
new T[10];
|
|
|
|
new T[n];
|
2009-09-24 02:59:48 +08:00
|
|
|
|
|
|
|
// Cookie required
|
|
|
|
new U[10];
|
|
|
|
new U[n];
|
2009-09-24 00:07:23 +08:00
|
|
|
}
|
2009-11-23 03:25:33 +08:00
|
|
|
|
|
|
|
void t9() {
|
|
|
|
bool b;
|
|
|
|
|
|
|
|
new bool(true);
|
|
|
|
new (&b) bool(true);
|
|
|
|
}
|
2009-11-25 02:29:37 +08:00
|
|
|
|
|
|
|
struct A {
|
|
|
|
void* operator new(__typeof(sizeof(int)), int, float, ...);
|
|
|
|
A();
|
|
|
|
};
|
|
|
|
|
|
|
|
A* t10() {
|
|
|
|
// CHECK: @_ZN1AnwEmifz
|
|
|
|
return new(1, 2, 3.45, 100) A;
|
|
|
|
}
|
|
|
|
|
2010-05-03 09:20:20 +08:00
|
|
|
struct B { int a; };
|
2009-12-16 14:57:54 +08:00
|
|
|
void t11() {
|
2009-12-17 00:59:22 +08:00
|
|
|
// CHECK: call noalias i8* @_Znwm
|
2010-04-04 11:10:52 +08:00
|
|
|
// CHECK: call void @llvm.memset.p0i8.i64(
|
2009-12-16 14:57:54 +08:00
|
|
|
B* b = new B();
|
|
|
|
}
|
2010-05-03 23:09:17 +08:00
|
|
|
|
|
|
|
struct Empty { };
|
|
|
|
|
|
|
|
// We don't need to initialize an empty class.
|
|
|
|
void t12() {
|
|
|
|
// CHECK: define void @_Z3t12v
|
|
|
|
// CHECK-NOT: br label
|
|
|
|
// CHECK: ret void
|
|
|
|
(void)new Empty[10];
|
|
|
|
}
|