1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -o - %s | FileCheck %s
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc extern "C" {
4*0a6a1f1dSLionel Sambuc
5*0a6a1f1dSLionel Sambuc #pragma const_seg(".my_const")
6*0a6a1f1dSLionel Sambuc #pragma bss_seg(".my_bss")
7*0a6a1f1dSLionel Sambuc int D = 1;
8*0a6a1f1dSLionel Sambuc #pragma data_seg(".data")
9*0a6a1f1dSLionel Sambuc int a = 1;
10*0a6a1f1dSLionel Sambuc #pragma data_seg(push, label, ".data2")
11*0a6a1f1dSLionel Sambuc extern const int b;
12*0a6a1f1dSLionel Sambuc const int b = 1;
13*0a6a1f1dSLionel Sambuc const char* s = "my string!";
14*0a6a1f1dSLionel Sambuc #pragma data_seg(push, ".my_seg")
15*0a6a1f1dSLionel Sambuc int c = 1;
16*0a6a1f1dSLionel Sambuc #pragma data_seg(pop, label)
17*0a6a1f1dSLionel Sambuc int d = 1;
18*0a6a1f1dSLionel Sambuc int e;
19*0a6a1f1dSLionel Sambuc #pragma bss_seg(".c")
20*0a6a1f1dSLionel Sambuc int f;
g(void)21*0a6a1f1dSLionel Sambuc void g(void){}
22*0a6a1f1dSLionel Sambuc #pragma code_seg(".my_code")
h(void)23*0a6a1f1dSLionel Sambuc void h(void){}
24*0a6a1f1dSLionel Sambuc #pragma bss_seg()
25*0a6a1f1dSLionel Sambuc int i;
26*0a6a1f1dSLionel Sambuc #pragma bss_seg(".bss1")
27*0a6a1f1dSLionel Sambuc #pragma bss_seg(push, test, ".bss2")
28*0a6a1f1dSLionel Sambuc #pragma bss_seg()
29*0a6a1f1dSLionel Sambuc #pragma bss_seg()
30*0a6a1f1dSLionel Sambuc int TEST1;
31*0a6a1f1dSLionel Sambuc #pragma bss_seg(pop)
32*0a6a1f1dSLionel Sambuc int TEST2;
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc #pragma section("read_flag_section", read)
35*0a6a1f1dSLionel Sambuc // Even though they are not declared const, these become constant since they are
36*0a6a1f1dSLionel Sambuc // in a read-only section.
37*0a6a1f1dSLionel Sambuc __declspec(allocate("read_flag_section")) int unreferenced = 0;
38*0a6a1f1dSLionel Sambuc extern __declspec(allocate("read_flag_section")) int referenced = 42;
user()39*0a6a1f1dSLionel Sambuc int *user() { return &referenced; }
40*0a6a1f1dSLionel Sambuc
41*0a6a1f1dSLionel Sambuc #pragma section("no_section_attributes")
42*0a6a1f1dSLionel Sambuc // A pragma section with no section attributes is read/write.
43*0a6a1f1dSLionel Sambuc __declspec(allocate("no_section_attributes")) int implicitly_read_write = 42;
44*0a6a1f1dSLionel Sambuc
45*0a6a1f1dSLionel Sambuc #pragma section("long_section", long)
46*0a6a1f1dSLionel Sambuc // Pragma section ignores "long".
47*0a6a1f1dSLionel Sambuc __declspec(allocate("long_section")) long long_var = 42;
48*0a6a1f1dSLionel Sambuc
49*0a6a1f1dSLionel Sambuc #pragma section("short_section", short)
50*0a6a1f1dSLionel Sambuc // Pragma section ignores "short".
51*0a6a1f1dSLionel Sambuc __declspec(allocate("short_section")) short short_var = 42;
52*0a6a1f1dSLionel Sambuc }
53*0a6a1f1dSLionel Sambuc
54*0a6a1f1dSLionel Sambuc //CHECK: @D = global i32 1
55*0a6a1f1dSLionel Sambuc //CHECK: @a = global i32 1, section ".data"
56*0a6a1f1dSLionel Sambuc //CHECK: @b = constant i32 1, section ".my_const"
57*0a6a1f1dSLionel Sambuc //CHECK: @[[MYSTR:.*]] = {{.*}} unnamed_addr constant [11 x i8] c"my string!\00"
58*0a6a1f1dSLionel Sambuc //CHECK: @s = global i8* getelementptr inbounds ([11 x i8]* @[[MYSTR]], i32 0, i32 0), section ".data2"
59*0a6a1f1dSLionel Sambuc //CHECK: @c = global i32 1, section ".my_seg"
60*0a6a1f1dSLionel Sambuc //CHECK: @d = global i32 1, section ".data"
61*0a6a1f1dSLionel Sambuc //CHECK: @e = global i32 0, section ".my_bss"
62*0a6a1f1dSLionel Sambuc //CHECK: @f = global i32 0, section ".c"
63*0a6a1f1dSLionel Sambuc //CHECK: @i = global i32 0
64*0a6a1f1dSLionel Sambuc //CHECK: @TEST1 = global i32 0
65*0a6a1f1dSLionel Sambuc //CHECK: @TEST2 = global i32 0, section ".bss1"
66*0a6a1f1dSLionel Sambuc //CHECK: @unreferenced = constant i32 0, section "read_flag_section"
67*0a6a1f1dSLionel Sambuc //CHECK: @referenced = constant i32 42, section "read_flag_section"
68*0a6a1f1dSLionel Sambuc //CHECK: @implicitly_read_write = global i32 42, section "no_section_attributes"
69*0a6a1f1dSLionel Sambuc //CHECK: @long_var = global i32 42, section "long_section"
70*0a6a1f1dSLionel Sambuc //CHECK: @short_var = global i16 42, section "short_section"
71*0a6a1f1dSLionel Sambuc //CHECK: define void @g()
72*0a6a1f1dSLionel Sambuc //CHECK: define void @h() {{.*}} section ".my_code"
73