File: sections.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (135 lines) | stat: -rw-r--r-- 5,313 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -verify -o - %s | FileCheck %s

extern "C" {

struct Mutable {
mutable int i = 3;
};
extern const Mutable mutable_default_section;
const Mutable mutable_default_section;
struct Normal {
  int i = 2;
};
extern const Normal normal_default_section;
const Normal normal_default_section;
#pragma const_seg(".my_const")
#pragma bss_seg(".my_bss")
int D = 1;
#pragma data_seg(".data")
int a = 1;
extern const Mutable mutable_custom_section;
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}}
extern const Normal normal_custom_section;
const Normal normal_custom_section;
struct NonTrivialDtor {
  ~NonTrivialDtor();
};
extern const NonTrivialDtor non_trivial_dtor_custom_section;
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}}
struct NonTrivialCtor {
  NonTrivialCtor();
};
extern const NonTrivialCtor non_trivial_ctor_custom_section;
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}}
#pragma data_seg(push, label, ".data2")
extern const int b;
const int b = 1;
const char* s = "my string!";
#pragma data_seg(push, ".my_seg")
int c = 1;
#pragma data_seg(pop, label)
int d = 1;
int e;
#pragma bss_seg(".c")
int f;
void g(void){}
#pragma code_seg(".my_code")
void h(void){}
#pragma bss_seg()
int i;
#pragma bss_seg(".bss1")
#pragma bss_seg(push, test, ".bss2")
#pragma bss_seg()
#pragma bss_seg()
int TEST1;
#pragma bss_seg(pop)
int TEST2;


// Check "save-restore" of pragma stacks.
struct Outer {
  void f() {
    #pragma bss_seg(push, ".bss3")
    #pragma code_seg(push, ".my_code1")
    #pragma const_seg(push, ".my_const1")
    #pragma data_seg(push, ".data3")
    struct Inner {
      void g() {
        #pragma bss_seg(push, ".bss4")
        #pragma code_seg(push, ".my_code2")
        #pragma const_seg(push, ".my_const2")
        #pragma data_seg(push, ".data4")
      }
    };
  }
};

void h2(void) {} // should be in ".my_code"
int TEST3; // should be in ".bss1"
int d2 = 1; // should be in ".data"
extern const int b2; // should be in ".my_const"
const int b2 = 1;

#pragma section("read_flag_section", read)
// Even though they are not declared const, these become constant since they are
// in a read-only section.
__declspec(allocate("read_flag_section")) int unreferenced = 0;
extern __declspec(allocate("read_flag_section")) int referenced = 42;
int *user() { return &referenced; }

#pragma section("no_section_attributes")
// A pragma section with no section attributes is read/write.
__declspec(allocate("no_section_attributes")) int implicitly_read_write = 42;

#pragma section("long_section", long)
// Pragma section ignores "long".
__declspec(allocate("long_section")) long long_var = 42;

#pragma section("short_section", short)
// Pragma section ignores "short".
__declspec(allocate("short_section")) short short_var = 42;

struct t2 { t2(); };
extern const t2 non_trivial_ctor;
__declspec(allocate("non_trivial_ctor_section")) const t2 non_trivial_ctor_var;
}


//CHECK: @mutable_default_section = dso_local global %struct.Mutable { i32 3 }, align 4{{$}}
//CHECK: @normal_default_section = dso_local constant %struct.Normal { i32 2 }, align 4{{$}}
//CHECK: @D = dso_local global i32 1
//CHECK: @a = dso_local global i32 1, section ".data"
//CHECK: @mutable_custom_section = dso_local global %struct.Mutable { i32 3 }, section ".data", align 4
//CHECK: @normal_custom_section = dso_local constant %struct.Normal { i32 2 }, section ".my_const", align 4
//CHECK: @b = dso_local constant i32 1, section ".my_const"
//CHECK: @[[MYSTR:.*]] = {{.*}} unnamed_addr constant [11 x i8] c"my string!\00"
//CHECK: @s = dso_local global ptr @[[MYSTR]], section ".data2"
//CHECK: @c = dso_local global i32 1, section ".my_seg"
//CHECK: @d = dso_local global i32 1, section ".data"
//CHECK: @e = dso_local global i32 0, section ".my_bss"
//CHECK: @f = dso_local global i32 0, section ".c"
//CHECK: @i = dso_local global i32 0
//CHECK: @TEST1 = dso_local global i32 0
//CHECK: @TEST2 = dso_local global i32 0, section ".bss1"
//CHECK: @TEST3 = dso_local global i32 0, section ".bss1"
//CHECK: @d2 = dso_local global i32 1, section ".data"
//CHECK: @b2 = dso_local constant i32 1, section ".my_const"
//CHECK: @unreferenced = dso_local constant i32 0, section "read_flag_section"
//CHECK: @referenced = dso_local constant i32 42, section "read_flag_section"
//CHECK: @implicitly_read_write = dso_local global i32 42, section "no_section_attributes"
//CHECK: @long_var = dso_local global i32 42, section "long_section"
//CHECK: @short_var = dso_local global i16 42, section "short_section"
//CHECK: @non_trivial_ctor_var = internal global %struct.t2 zeroinitializer, section "non_trivial_ctor_section"
//CHECK: define dso_local void @g()
//CHECK: define dso_local void @h() {{.*}} section ".my_code"
//CHECK: define dso_local void @h2() {{.*}} section ".my_code"