[InstCombine] Preserve NSW flags for `lshr (mul nuw X, C1), C2 -> mul nuw nsw X,...
[llvm-project.git] / clang / test / CodeGenCXX / sections.cpp
blobc7fe4e45ea05a60972f68edc62dfe17e1c89468a
1 // RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -verify -o - %s | FileCheck %s
3 extern "C" {
5 struct Mutable {
6 mutable int i = 3;
7 };
8 extern const Mutable mutable_default_section;
9 const Mutable mutable_default_section;
10 struct Normal {
11 int i = 2;
13 extern const Normal normal_default_section;
14 const Normal normal_default_section;
15 #pragma const_seg(".my_const")
16 #pragma bss_seg(".my_bss")
17 int D = 1;
18 #pragma data_seg(".data")
19 int a = 1;
20 extern const Mutable mutable_custom_section;
21 const 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}}
22 extern const Normal normal_custom_section;
23 const Normal normal_custom_section;
24 struct NonTrivialDtor {
25 ~NonTrivialDtor();
27 extern const NonTrivialDtor non_trivial_dtor_custom_section;
28 const 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}}
29 struct NonTrivialCtor {
30 NonTrivialCtor();
32 extern const NonTrivialCtor non_trivial_ctor_custom_section;
33 const 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")
35 extern const int b;
36 const int b = 1;
37 const char* s = "my string!";
38 #pragma data_seg(push, ".my_seg")
39 int c = 1;
40 #pragma data_seg(pop, label)
41 int d = 1;
42 int e;
43 #pragma bss_seg(".c")
44 int f;
45 void g(void){}
46 #pragma code_seg(".my_code")
47 void h(void){}
48 #pragma bss_seg()
49 int i;
50 #pragma bss_seg(".bss1")
51 #pragma bss_seg(push, test, ".bss2")
52 #pragma bss_seg()
53 #pragma bss_seg()
54 int TEST1;
55 #pragma bss_seg(pop)
56 int TEST2;
59 // Check "save-restore" of pragma stacks.
60 struct 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")
77 void h2(void) {} // should be in ".my_code"
78 int TEST3; // should be in ".bss1"
79 int d2 = 1; // should be in ".data"
80 extern const int b2; // should be in ".my_const"
81 const int b2 = 1;
83 #pragma section("read_flag_section", read)
84 // Even though they are not declared const, these become constant since they are
85 // in a read-only section.
86 __declspec(allocate("read_flag_section")) int unreferenced = 0;
87 extern __declspec(allocate("read_flag_section")) int referenced = 42;
88 int *user() { return &referenced; }
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;
94 #pragma section("long_section", long)
95 // Pragma section ignores "long".
96 __declspec(allocate("long_section")) long long_var = 42;
98 #pragma section("short_section", short)
99 // Pragma section ignores "short".
100 __declspec(allocate("short_section")) short short_var = 42;
102 struct t2 { t2(); };
103 extern const t2 non_trivial_ctor;
104 __declspec(allocate("non_trivial_ctor_section")) const t2 non_trivial_ctor_var;
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 1
111 //CHECK: @a = dso_local global i32 1, section ".data"
112 //CHECK: @mutable_custom_section = dso_local global %struct.Mutable { i32 3 }, section ".data", align 4
113 //CHECK: @normal_custom_section = dso_local constant %struct.Normal { i32 2 }, section ".my_const", align 4
114 //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 0
122 //CHECK: @TEST1 = dso_local global i32 0
123 //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"