Don't emit structors for available_externally globals (PR19933)
[oota-llvm.git] / test / MC / COFF / global_ctors_dtors.ll
1 ; Test that global ctors are emitted into the proper COFF section for the
2 ; target. Mingw uses .ctors, whereas MSVC uses .CRT$XC*.
3 ; RUN: llc < %s -mtriple i686-pc-win32 | FileCheck %s --check-prefix WIN32
4 ; RUN: llc < %s -mtriple x86_64-pc-win32 | FileCheck %s --check-prefix WIN32
5 ; RUN: llc < %s -mtriple i686-pc-mingw32 | FileCheck %s --check-prefix MINGW32
6 ; RUN: llc < %s -mtriple x86_64-pc-mingw32 | FileCheck %s --check-prefix MINGW32
7
8 @.str = private unnamed_addr constant [13 x i8] c"constructing\00", align 1
9 @.str2 = private unnamed_addr constant [12 x i8] c"destructing\00", align 1
10 @.str3 = private unnamed_addr constant [5 x i8] c"main\00", align 1
11
12 %ini = type { i32, void()*, i8* }
13
14 @llvm.global_ctors = appending global [3 x %ini ] [
15   %ini { i32 65535, void ()* @a_global_ctor, i8* null },
16   %ini { i32 65535, void ()* @b_global_ctor, i8* bitcast (i32* @b to i8*) },
17   %ini { i32 65535, void ()* @c_global_ctor, i8* bitcast (i32* @c to i8*) }
18 ]
19 @llvm.global_dtors = appending global [1 x %ini ] [%ini { i32 65535, void ()* @a_global_dtor, i8* null }]
20
21 declare i32 @puts(i8*)
22
23 define void @a_global_ctor() nounwind {
24   %1 = call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0))
25   ret void
26 }
27
28 @b = global i32 zeroinitializer
29
30 @c = available_externally dllimport global i32 zeroinitializer
31
32 define void @b_global_ctor() nounwind {
33   store i32 42, i32* @b
34   ret void
35 }
36
37 define void @c_global_ctor() nounwind {
38   store i32 42, i32* @c
39   ret void
40 }
41
42 define void @a_global_dtor() nounwind {
43   %1 = call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str2, i32 0, i32 0))
44   ret void
45 }
46
47 define i32 @main() nounwind {
48   %1 = call i32 @puts(i8* getelementptr inbounds ([5 x i8]* @.str3, i32 0, i32 0))
49   ret i32 0
50 }
51
52 ; WIN32: .section .CRT$XCU,"rd"
53 ; WIN32: a_global_ctor
54 ; WIN32: .section .CRT$XCU,"rd",associative .bss,{{_?}}b
55 ; WIN32: b_global_ctor
56 ; WIN32-NOT: c_global_ctor
57 ; WIN32: .section .CRT$XTX,"rd"
58 ; WIN32: a_global_dtor
59 ; MINGW32: .section .ctors,"wd"
60 ; MINGW32: a_global_ctor
61 ; MINGW32: .section .ctors,"wd",associative .bss,{{_?}}b
62 ; MINGW32: b_global_ctor
63 ; MINGW32-NOT: c_global_ctor
64 ; MINGW32: .section .dtors,"wd"
65 ; MINGW32: a_global_dtor