blob: a96cb7ac8e02a5664f33486b640a7dc4a014fb7a [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
Anders Carlsson071c8102010-01-26 04:02:23 +00002
3// CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
Eli Friedman8b42ab72012-03-09 03:06:56 +00004// CHECK: @base_req = global [4 x i8] c"foo\00", align 1
Anders Carlssonf6b89a12010-02-07 02:03:08 +00005
John McCall78951942011-03-22 06:58:49 +00006// CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16
John McCall8b242332010-05-25 04:30:21 +00007// CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0
8// CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0
Anders Carlssonf6b89a12010-02-07 02:03:08 +00009
Anders Carlsson3b2e16b2009-08-08 21:45:14 +000010struct A {
11 A();
12 ~A();
13};
14
15void f() {
Eli Friedmaneb43f4a2011-09-13 22:21:56 +000016 // CHECK: load atomic i8* bitcast (i64* @_ZGVZ1fvE1a to i8*) acquire, align 1
Douglas Gregorcc6a44b2010-05-05 15:38:32 +000017 // CHECK: call i32 @__cxa_guard_acquire
18 // CHECK: call void @_ZN1AC1Ev
Anders Carlssonc7974ca2009-12-10 01:05:11 +000019 // CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @_ZZ1fvE1a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
John McCall5cd91b52010-09-08 01:44:27 +000020 // CHECK: call void @__cxa_guard_release
Anders Carlsson3b2e16b2009-08-08 21:45:14 +000021 static A a;
22}
23
Anders Carlssonc7974ca2009-12-10 01:05:11 +000024void g() {
Nuno Lopesfc284482009-12-16 16:59:22 +000025 // CHECK: call noalias i8* @_Znwm(i64 1)
Anders Carlssonc7974ca2009-12-10 01:05:11 +000026 // CHECK: call void @_ZN1AC1Ev(
27 static A& a = *new A;
28}
Anders Carlsson071c8102010-01-26 04:02:23 +000029
30int a();
31void h() {
32 static const int i = a();
33}
Anders Carlssonf6b89a12010-02-07 02:03:08 +000034
35inline void h2() {
36 static int i = a();
37}
38
39void h3() {
40 h2();
41}
John McCalle65ce962010-05-03 21:39:56 +000042
43// PR6980: this shouldn't crash
44namespace test0 {
45 struct A { A(); };
46 __attribute__((noreturn)) int throw_exception();
47
48 void test() {
49 throw_exception();
50 static A r;
51 }
52}
John McCall8b242332010-05-25 04:30:21 +000053
54namespace test1 {
John McCall78951942011-03-22 06:58:49 +000055 // CHECK: define internal i32 @_ZN5test1L6getvarEi(
John McCall8b242332010-05-25 04:30:21 +000056 static inline int getvar(int index) {
57 static const int var[] = { 1, 0, 2, 4 };
58 return var[index];
59 }
60
61 void test() { (void) getvar(2); }
62}
Eli Friedman8b42ab72012-03-09 03:06:56 +000063
64// Make sure we emit the initializer correctly for the following:
65char base_req[] = { "foo" };
Eli Friedman71cba342012-03-09 03:27:46 +000066
67namespace union_static_local {
68 // CHECK: define internal void @_ZZN18union_static_local4testEvEN1c4mainEv
69 // CHECK: call void @_ZN18union_static_local1fEPNS_1xE(%"union.union_static_local::x"* bitcast ({ [2 x i8*] }* @_ZZN18union_static_local4testEvE3foo to %"union.union_static_local::x"*))
70 union x { long double y; const char *x[2]; };
71 void f(union x*);
72 void test() {
73 static union x foo = { .x = { "a", "b" } };
74 struct c {
75 static void main() {
76 f(&foo);
77 }
78 };
79 c::main();
80 }
81}