xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/init-priority-attr.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -O2 -emit-llvm -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc // PR11480
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc void foo(int);
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc class A {
7f4a2713aSLionel Sambuc public:
A()8f4a2713aSLionel Sambuc   A() { foo(1); }
9f4a2713aSLionel Sambuc };
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc class A1 {
12f4a2713aSLionel Sambuc public:
A1()13f4a2713aSLionel Sambuc   A1() { foo(2); }
14f4a2713aSLionel Sambuc };
15f4a2713aSLionel Sambuc 
16f4a2713aSLionel Sambuc class B {
17f4a2713aSLionel Sambuc public:
B()18f4a2713aSLionel Sambuc   B() { foo(3); }
19f4a2713aSLionel Sambuc };
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc class C {
22f4a2713aSLionel Sambuc public:
23f4a2713aSLionel Sambuc   static A a;
C()24f4a2713aSLionel Sambuc   C() { foo(4); }
25f4a2713aSLionel Sambuc };
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc 
28f4a2713aSLionel Sambuc A C::a = A();
29f4a2713aSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc // CHECK: @llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }]
31*0a6a1f1dSLionel Sambuc // CHECK: [{ i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__I_000200, i8* null },
32*0a6a1f1dSLionel Sambuc // CHECK:  { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__I_000300, i8* null },
33*0a6a1f1dSLionel Sambuc // CHECK:  { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_init_priority_attr.cpp, i8* null }]
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc // CHECK: _GLOBAL__I_000200()
36*0a6a1f1dSLionel Sambuc // CHECK: _Z3fooi(i32 3)
37*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret void
38f4a2713aSLionel Sambuc 
39f4a2713aSLionel Sambuc // CHECK: _GLOBAL__I_000300()
40*0a6a1f1dSLionel Sambuc // CHECK: _Z3fooi(i32 2)
41*0a6a1f1dSLionel Sambuc // CHECK-NEXT: _Z3fooi(i32 1)
42*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret void
43f4a2713aSLionel Sambuc 
44*0a6a1f1dSLionel Sambuc // CHECK: _GLOBAL__sub_I_init_priority_attr.cpp()
45*0a6a1f1dSLionel Sambuc // CHECK: _Z3fooi(i32 1)
46*0a6a1f1dSLionel Sambuc // CHECK-NEXT: _Z3fooi(i32 4)
47*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ret void
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc C c;
50f4a2713aSLionel Sambuc A1 a1 __attribute__((init_priority (300)));
51f4a2713aSLionel Sambuc A a __attribute__((init_priority (300)));
52f4a2713aSLionel Sambuc B b __attribute__((init_priority (200)));
53