]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenCXX/static-init.cpp
Vendor import of clang trunk r135360:
[FreeBSD/FreeBSD.git] / test / CodeGenCXX / static-init.cpp
1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2
3 // CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
4
5 // CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16
6 // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0
7 // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0
8
9 struct A {
10   A();
11   ~A();
12 };
13
14 void f() {
15   // CHECK: call i32 @__cxa_guard_acquire
16   // CHECK: call void @_ZN1AC1Ev
17   // 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*))
18   // CHECK: call void @__cxa_guard_release
19
20   // rdar://problem/9496726
21   // CHECK: call void @llvm.memory.barrier(i1 true, i1 true, i1 false, i1 false, i1 false)
22   static A a;
23 }
24
25 void g() {
26   // CHECK: call noalias i8* @_Znwm(i64 1)
27   // CHECK: call void @_ZN1AC1Ev(
28   static A& a = *new A;
29 }
30
31 int a();
32 void h() {
33   static const int i = a();
34 }
35
36 inline void h2() {
37   static int i = a();
38 }
39
40 void h3() {
41   h2();
42 }
43
44 // PR6980: this shouldn't crash
45 namespace test0 {
46   struct A { A(); };
47   __attribute__((noreturn)) int throw_exception();
48
49   void test() {
50     throw_exception();
51     static A r;
52   }
53 }
54
55 namespace test1 {
56   // CHECK: define internal i32 @_ZN5test1L6getvarEi(
57   static inline int getvar(int index) {
58     static const int var[] = { 1, 0, 2, 4 };
59     return var[index];
60   }
61
62   void test() { (void) getvar(2); }
63 }