blob: 8dd3b4eb14b353ea0f7da5cbed79a1689d017bbf [file] [log] [blame]
John McCall044cc542010-07-06 04:38:10 +00001// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fexceptions %s -o - |FileCheck %s
2// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck -check-prefix NOEXC %s
Anders Carlsson89ed31d2009-08-08 23:24:23 +00003
4struct A {
5 A();
6 ~A();
7};
8
Anders Carlsson74d644a2009-10-08 17:28:59 +00009struct B { B(); ~B(); };
10
John McCallfb8b69a2010-02-02 08:02:49 +000011struct C { void *field; };
12
Anders Carlsson2ca4f632010-02-05 18:38:45 +000013struct D { ~D(); };
14
John McCallfb8b69a2010-02-02 08:02:49 +000015// CHECK: @c = global %struct.C zeroinitializer, align 8
16
Anders Carlsson74d644a2009-10-08 17:28:59 +000017// CHECK: call void @_ZN1AC1Ev(%struct.A* @a)
Anders Carlssona3f36ab2009-10-08 17:22:47 +000018// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
Anders Carlsson89ed31d2009-08-08 23:24:23 +000019A a;
Anders Carlsson74d644a2009-10-08 17:28:59 +000020
21// CHECK: call void @_ZN1BC1Ev(%struct.A* @b)
22// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @b, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
23B b;
John McCallfb8b69a2010-02-02 08:02:49 +000024
25// PR6205: this should not require a global initializer
26// CHECK-NOT: call void @_ZN1CC1Ev(%struct.C* @c)
27C c;
28
Anders Carlsson2ca4f632010-02-05 18:38:45 +000029// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1DD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @d, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
30D d;
31
John McCallbf40cb52010-07-15 23:40:35 +000032// <rdar://problem/7458115>
33namespace test1 {
34 int f();
35 const int x = f(); // This has side-effects and gets emitted immediately.
36 const int y = x - 1; // This gets deferred.
37 const int z = ~y; // This also gets deferred, but gets "undeferred" before y.
38 int test() { return z; }
39// CHECK: define i32 @_ZN5test14testEv() {
40// CHECK: define internal void [[TEST1_Z_INIT:@.*]]()
41// CHECK: load i32* @_ZN5test1L1yE
42// CHECK-NEXT: xor
43// CHECK-NEXT: store i32 {{.*}}, i32* @_ZN5test1L1zE
44// CHECK: define internal void [[TEST1_Y_INIT:@.*]]()
45// CHECK: load i32* @_ZN5test1L1xE
46// CHECK-NEXT: sub
47// CHECK-NEXT: store i32 {{.*}}, i32* @_ZN5test1L1yE
48
49// Later on, we check that y is initialized before z.
50}
51
Anders Carlsson9df792c2010-06-09 01:42:52 +000052// CHECK: define internal void @_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" {
John McCallbf40cb52010-07-15 23:40:35 +000053// CHECK: call void [[TEST1_Y_INIT]]
54// CHECK: call void [[TEST1_Z_INIT]]
Anders Carlsson9df792c2010-06-09 01:42:52 +000055
John McCall044cc542010-07-06 04:38:10 +000056// rdar://problem/8090834: this should be nounwind
57// CHECK-NOEXC: define internal void @_GLOBAL__I_a() nounwind section "__TEXT,__StaticInit,regular,pure_instructions" {