| 1 | // RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -o - %s | FileCheck %s |
| 2 | |
| 3 | extern "C" { |
| 4 | |
| 5 | #pragma const_seg(".my_const") |
| 6 | #pragma bss_seg(".my_bss") |
| 7 | int D = 1; |
| 8 | #pragma data_seg(".data") |
| 9 | int a = 1; |
| 10 | #pragma data_seg(push, label, ".data2") |
| 11 | extern const int b; |
| 12 | const int b = 1; |
| 13 | const char* s = "my string!"; |
| 14 | #pragma data_seg(push, ".my_seg") |
| 15 | int c = 1; |
| 16 | #pragma data_seg(pop, label) |
| 17 | int d = 1; |
| 18 | int e; |
| 19 | #pragma bss_seg(".c") |
| 20 | int f; |
| 21 | void g(void){} |
| 22 | #pragma code_seg(".my_code") |
| 23 | void h(void){} |
| 24 | #pragma bss_seg() |
| 25 | int i; |
| 26 | #pragma bss_seg(".bss1") |
| 27 | #pragma bss_seg(push, test, ".bss2") |
| 28 | #pragma bss_seg() |
| 29 | #pragma bss_seg() |
| 30 | int TEST1; |
| 31 | #pragma bss_seg(pop) |
| 32 | int TEST2; |
| 33 | |
| 34 | |
| 35 | // Check "save-restore" of pragma stacks. |
| 36 | struct Outer { |
| 37 | void f() { |
| 38 | #pragma bss_seg(push, ".bss3") |
| 39 | #pragma code_seg(push, ".my_code1") |
| 40 | #pragma const_seg(push, ".my_const1") |
| 41 | #pragma data_seg(push, ".data3") |
| 42 | struct Inner { |
| 43 | void g() { |
| 44 | #pragma bss_seg(push, ".bss4") |
| 45 | #pragma code_seg(push, ".my_code2") |
| 46 | #pragma const_seg(push, ".my_const2") |
| 47 | #pragma data_seg(push, ".data4") |
| 48 | } |
| 49 | }; |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | void h2(void) {} // should be in ".my_code" |
| 54 | int TEST3; // should be in ".bss1" |
| 55 | int d2 = 1; // should be in ".data" |
| 56 | extern const int b2; // should be in ".my_const" |
| 57 | const int b2 = 1; |
| 58 | |
| 59 | #pragma section("read_flag_section", read) |
| 60 | // Even though they are not declared const, these become constant since they are |
| 61 | // in a read-only section. |
| 62 | __declspec(allocate("read_flag_section")) int unreferenced = 0; |
| 63 | extern __declspec(allocate("read_flag_section")) int referenced = 42; |
| 64 | int *user() { return &referenced; } |
| 65 | |
| 66 | #pragma section("no_section_attributes") |
| 67 | // A pragma section with no section attributes is read/write. |
| 68 | __declspec(allocate("no_section_attributes")) int implicitly_read_write = 42; |
| 69 | |
| 70 | #pragma section("long_section", long) |
| 71 | // Pragma section ignores "long". |
| 72 | __declspec(allocate("long_section")) long long_var = 42; |
| 73 | |
| 74 | #pragma section("short_section", short) |
| 75 | // Pragma section ignores "short". |
| 76 | __declspec(allocate("short_section")) short short_var = 42; |
| 77 | } |
| 78 | |
| 79 | //CHECK: @D = dso_local global i32 1 |
| 80 | //CHECK: @a = dso_local global i32 1, section ".data" |
| 81 | //CHECK: @b = dso_local constant i32 1, section ".my_const" |
| 82 | //CHECK: @[[MYSTR:.*]] = {{.*}} unnamed_addr constant [11 x i8] c"my string!\00" |
| 83 | //CHECK: @s = dso_local global i8* getelementptr inbounds ([11 x i8], [11 x i8]* @[[MYSTR]], i32 0, i32 0), section ".data2" |
| 84 | //CHECK: @c = dso_local global i32 1, section ".my_seg" |
| 85 | //CHECK: @d = dso_local global i32 1, section ".data" |
| 86 | //CHECK: @e = dso_local global i32 0, section ".my_bss" |
| 87 | //CHECK: @f = dso_local global i32 0, section ".c" |
| 88 | //CHECK: @i = dso_local global i32 0 |
| 89 | //CHECK: @TEST1 = dso_local global i32 0 |
| 90 | //CHECK: @TEST2 = dso_local global i32 0, section ".bss1" |
| 91 | //CHECK: @TEST3 = dso_local global i32 0, section ".bss1" |
| 92 | //CHECK: @d2 = dso_local global i32 1, section ".data" |
| 93 | //CHECK: @b2 = dso_local constant i32 1, section ".my_const" |
| 94 | //CHECK: @unreferenced = dso_local constant i32 0, section "read_flag_section" |
| 95 | //CHECK: @referenced = dso_local constant i32 42, section "read_flag_section" |
| 96 | //CHECK: @implicitly_read_write = dso_local global i32 42, section "no_section_attributes" |
| 97 | //CHECK: @long_var = dso_local global i32 42, section "long_section" |
| 98 | //CHECK: @short_var = dso_local global i16 42, section "short_section" |
| 99 | //CHECK: define dso_local void @g() |
| 100 | //CHECK: define dso_local void @h() {{.*}} section ".my_code" |
| 101 | //CHECK: define dso_local void @h2() {{.*}} section ".my_code" |
| 102 | |