]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenCXX/static-data-member.cpp
Vendor import of clang trunk r126079:
[FreeBSD/FreeBSD.git] / test / CodeGenCXX / static-data-member.cpp
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
2
3 // CHECK: @_ZN5test11A1aE = constant i32 10, align 4
4 // CHECK: @_ZN5test212_GLOBAL__N_11AIiE1xE = internal global i32 0, align 4
5 // CHECK: @_ZN5test31AIiE1xE = weak global i32 0, align 4
6 // CHECK: @_ZGVN5test31AIiE1xE = weak global i64 0
7
8 // PR5564.
9 namespace test1 {
10   struct A {
11     static const int a = 10;
12   };
13
14   const int A::a;
15
16   struct S { 
17     static int i;
18   };
19
20   void f() { 
21     int a = S::i;
22   }
23 }
24
25 // Test that we don't use guards for initializing template static data
26 // members with internal linkage.
27 namespace test2 {
28   int foo();
29
30   namespace {
31     template <class T> struct A {
32       static int x;
33     };
34
35     template <class T> int A<T>::x = foo();
36     template struct A<int>;
37   }
38
39   // CHECK: define internal void @__cxx_global_var_init()
40   // CHECK:      [[TMP:%.*]] = call i32 @_ZN5test23fooEv()
41   // CHECK-NEXT: store i32 [[TMP]], i32* @_ZN5test212_GLOBAL__N_11AIiE1xE, align 4
42   // CHECK-NEXT: ret void
43 }
44
45 // Test that we don't use threadsafe statics when initializing
46 // template static data members.
47 namespace test3 {
48   int foo();
49
50   template <class T> struct A {
51     static int x;
52   };
53
54   template <class T> int A<T>::x = foo();
55   template struct A<int>;
56
57   // CHECK: define internal void @__cxx_global_var_init1()
58   // CHECK:      [[GUARDBYTE:%.*]] = load i8* bitcast (i64* @_ZGVN5test31AIiE1xE to i8*)
59   // CHECK-NEXT: [[UNINITIALIZED:%.*]] = icmp eq i8 [[GUARDBYTE]], 0
60   // CHECK-NEXT: br i1 [[UNINITIALIZED]]
61   // CHECK:      [[TMP:%.*]] = call i32 @_ZN5test33fooEv()
62   // CHECK-NEXT: store i32 [[TMP]], i32* @_ZN5test31AIiE1xE, align 4
63   // CHECK-NEXT: store i64 1, i64* @_ZGVN5test31AIiE1xE
64   // CHECK-NEXT: br label
65   // CHECK:      ret void
66 }