brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · 88efd76 Raw
136 lines · cpp
1// RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -verify -o - %s | FileCheck %s2 3extern "C" {4 5struct Mutable {6mutable int i = 3;7};8extern const Mutable mutable_default_section;9const Mutable mutable_default_section;10struct Normal {11  int i = 2;12};13extern const Normal normal_default_section;14const Normal normal_default_section;15#pragma const_seg(".my_const")16#pragma bss_seg(".my_bss")17int D = 1;18#pragma data_seg(".data")19int a = 1;20extern const Mutable mutable_custom_section;21const Mutable mutable_custom_section; // expected-warning {{`#pragma const_seg` for section '".my_const"' will not apply to 'mutable_custom_section' due to the presence of a mutable field}}22extern const Normal normal_custom_section;23const Normal normal_custom_section;24struct NonTrivialDtor {25  ~NonTrivialDtor();26};27extern const NonTrivialDtor non_trivial_dtor_custom_section;28const NonTrivialDtor non_trivial_dtor_custom_section; // expected-warning {{`#pragma const_seg` for section '".my_const"' will not apply to 'non_trivial_dtor_custom_section' due to the presence of a non-trivial destructor}}29struct NonTrivialCtor {30  NonTrivialCtor();31};32extern const NonTrivialCtor non_trivial_ctor_custom_section;33const NonTrivialCtor non_trivial_ctor_custom_section; // expected-warning {{`#pragma const_seg` for section '".my_const"' will not apply to 'non_trivial_ctor_custom_section' due to the presence of a non-trivial constructor}}34#pragma data_seg(push, label, ".data2")35extern const int b;36const int b = 1;37const char* s = "my string!";38#pragma data_seg(push, ".my_seg")39int c = 1;40#pragma data_seg(pop, label)41int d = 1;42int e;43#pragma bss_seg(".c")44int f;45void g(void){}46#pragma code_seg(".my_code")47void h(void){}48#pragma bss_seg()49int i;50#pragma bss_seg(".bss1")51#pragma bss_seg(push, test, ".bss2")52#pragma bss_seg()53#pragma bss_seg()54int TEST1;55#pragma bss_seg(pop)56int TEST2;57 58 59// Check "save-restore" of pragma stacks.60struct Outer {61  void f() {62    #pragma bss_seg(push, ".bss3")63    #pragma code_seg(push, ".my_code1")64    #pragma const_seg(push, ".my_const1")65    #pragma data_seg(push, ".data3")66    struct Inner {67      void g() {68        #pragma bss_seg(push, ".bss4")69        #pragma code_seg(push, ".my_code2")70        #pragma const_seg(push, ".my_const2")71        #pragma data_seg(push, ".data4")72      }73    };74  }75};76 77void h2(void) {} // should be in ".my_code"78int TEST3; // should be in ".bss1"79int d2 = 1; // should be in ".data"80extern const int b2; // should be in ".my_const"81const int b2 = 1;82 83#pragma section("read_flag_section", read)84// Even though they are not declared const, these become constant since they are85// in a read-only section.86__declspec(allocate("read_flag_section")) int unreferenced = 0;87extern __declspec(allocate("read_flag_section")) int referenced = 42;88int *user() { return &referenced; }89 90#pragma section("no_section_attributes")91// A pragma section with no section attributes is read/write.92__declspec(allocate("no_section_attributes")) int implicitly_read_write = 42;93 94#pragma section("long_section", long)95// Pragma section ignores "long".96__declspec(allocate("long_section")) long long_var = 42;97 98#pragma section("short_section", short)99// Pragma section ignores "short".100__declspec(allocate("short_section")) short short_var = 42;101 102struct t2 { t2(); };103extern const t2 non_trivial_ctor;104__declspec(allocate("non_trivial_ctor_section")) const t2 non_trivial_ctor_var;105}106 107 108//CHECK: @mutable_default_section = dso_local global %struct.Mutable { i32 3 }, align 4{{$}}109//CHECK: @normal_default_section = dso_local constant %struct.Normal { i32 2 }, align 4{{$}}110//CHECK: @D = dso_local global i32 1111//CHECK: @a = dso_local global i32 1, section ".data"112//CHECK: @mutable_custom_section = dso_local global %struct.Mutable { i32 3 }, section ".data", align 4113//CHECK: @normal_custom_section = dso_local constant %struct.Normal { i32 2 }, section ".my_const", align 4114//CHECK: @b = dso_local constant i32 1, section ".my_const"115//CHECK: @[[MYSTR:.*]] = {{.*}} unnamed_addr constant [11 x i8] c"my string!\00"116//CHECK: @s = dso_local global ptr @[[MYSTR]], section ".data2"117//CHECK: @c = dso_local global i32 1, section ".my_seg"118//CHECK: @d = dso_local global i32 1, section ".data"119//CHECK: @e = dso_local global i32 0, section ".my_bss"120//CHECK: @f = dso_local global i32 0, section ".c"121//CHECK: @i = dso_local global i32 0122//CHECK: @TEST1 = dso_local global i32 0123//CHECK: @TEST2 = dso_local global i32 0, section ".bss1"124//CHECK: @TEST3 = dso_local global i32 0, section ".bss1"125//CHECK: @d2 = dso_local global i32 1, section ".data"126//CHECK: @b2 = dso_local constant i32 1, section ".my_const"127//CHECK: @unreferenced = dso_local constant i32 0, section "read_flag_section"128//CHECK: @referenced = dso_local constant i32 42, section "read_flag_section"129//CHECK: @implicitly_read_write = dso_local global i32 42, section "no_section_attributes"130//CHECK: @long_var = dso_local global i32 42, section "long_section"131//CHECK: @short_var = dso_local global i16 42, section "short_section"132//CHECK: @non_trivial_ctor_var = internal global %struct.t2 zeroinitializer, section "non_trivial_ctor_section"133//CHECK: define dso_local void @g()134//CHECK: define dso_local void @h() {{.*}} section ".my_code"135//CHECK: define dso_local void @h2() {{.*}} section ".my_code"136