Clang Project

clang_source_code/test/CodeGenCXX/clang-sections-tentative.c
1// RUN: %clang_cc1 -x c -emit-llvm -triple arm-none-eabi -o - %s | FileCheck %s
2
3// Test that section attributes are attached to C tentative definitions as per
4// '#pragma clang section' directives.
5
6#pragma clang section bss = ".bss.1"
7int x; // bss.1
8
9#pragma clang section bss = ""
10int x; // stays in .bss.1
11int y; // not assigned a section attribute
12int z; // not assigned a section attribute
13
14#pragma clang section bss = ".bss.2"
15int x; // stays in .bss.1
16int y; // .bss.2
17
18// Test the same for `const` declarations.
19#pragma clang section rodata = ".rodata.1"
20const int cx; // rodata.1
21
22#pragma clang section rodata = ""
23const int cx; // stays in .rodata.1
24const int cy; // not assigned a section attribute
25const int cz; // not assigned a rodata section attribute
26
27#pragma clang section rodata = ".rodata.2"
28const int cx; // stays in .rodata.1
29const int cy; // .rodata.2
30
31// CHECK: @x = global i32 0, align 4 #0
32// CHECK: @y = global i32 0, align 4 #1
33// CHECK: @z = common global i32 0, align 4
34// CHECK: @cx = constant i32 0, align 4 #2
35// CHECK: @cy = constant i32 0, align 4 #3
36// CHECK: @cz = constant i32 0, align 4 #1
37
38// CHECK: attributes #0 = { "bss-section"=".bss.1" }
39// CHECK: attributes #1 = { "bss-section"=".bss.2" }
40// CHECK: attributes #2 = { "bss-section"=".bss.2" "rodata-section"=".rodata.1" }
41// CHECK: attributes #3 = { "bss-section"=".bss.2" "rodata-section"=".rodata.2" }
42