Javed Absar | 2a67c9e | 2017-06-05 10:11:57 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -triple arm-none-eabi -o - %s | FileCheck %s |
| 2 | // Test that global variables, statics and functions are attached section-attributes |
| 3 | // as per '#pragma clang section' directives. |
| 4 | |
| 5 | extern "C" { |
| 6 | // test with names for each section |
| 7 | #pragma clang section bss="my_bss.1" data="my_data.1" rodata="my_rodata.1" |
| 8 | #pragma clang section text="my_text.1" |
| 9 | int a; // my_bss.1 |
| 10 | int b = 1; // my_data.1 |
| 11 | int c[4]; // my_bss.1 |
| 12 | short d[5] = {0}; // my_bss.1 |
| 13 | short e[6] = {0, 0, 1}; // my_data.1 |
| 14 | extern const int f; |
| 15 | const int f = 2; // my_rodata.1 |
| 16 | int foo(void) { // my_text.1 |
| 17 | return b; |
| 18 | } |
| 19 | static int g[2]; // my_bss.1 |
| 20 | #pragma clang section bss="" |
| 21 | int h; // default - .bss |
| 22 | #pragma clang section data="" bss="my_bss.2" text="my_text.2" |
| 23 | int i = 0; // my_bss.2 |
| 24 | extern const int j; |
| 25 | const int j = 4; // default - .rodata |
| 26 | int k; // my_bss.2 |
| 27 | extern int zoo(int *x, int *y); |
| 28 | int goo(void) { // my_text.2 |
| 29 | static int lstat_h; // my_bss.2 |
| 30 | return zoo(g, &lstat_h); |
| 31 | } |
| 32 | #pragma clang section rodata="my_rodata.2" data="my_data.2" |
| 33 | int l = 5; // my_data.2 |
| 34 | extern const int m; |
| 35 | const int m = 6; // my_rodata.2 |
| 36 | #pragma clang section rodata="" data="" bss="" text="" |
| 37 | int n; // default |
| 38 | int o = 6; // default |
| 39 | extern const int p; |
| 40 | const int p = 7; // default |
| 41 | int hoo(void) { |
| 42 | return b; |
| 43 | } |
| 44 | } |
| 45 | //CHECK: @a = global i32 0, align 4 #0 |
| 46 | //CHECK: @b = global i32 1, align 4 #0 |
| 47 | //CHECK: @c = global [4 x i32] zeroinitializer, align 4 #0 |
| 48 | //CHECK: @d = global [5 x i16] zeroinitializer, align 2 #0 |
| 49 | //CHECK: @e = global [6 x i16] [i16 0, i16 0, i16 1, i16 0, i16 0, i16 0], align 2 #0 |
| 50 | //CHECK: @f = constant i32 2, align 4 #0 |
| 51 | |
| 52 | //CHECK: @h = global i32 0, align 4 #1 |
| 53 | //CHECK: @i = global i32 0, align 4 #2 |
| 54 | //CHECK: @j = constant i32 4, align 4 #2 |
| 55 | //CHECK: @k = global i32 0, align 4 #2 |
| 56 | //CHECK: @_ZZ3gooE7lstat_h = internal global i32 0, align 4 #2 |
| 57 | //CHECK: @_ZL1g = internal global [2 x i32] zeroinitializer, align 4 #0 |
| 58 | |
| 59 | //CHECK: @l = global i32 5, align 4 #3 |
| 60 | //CHECK: @m = constant i32 6, align 4 #3 |
| 61 | |
| 62 | //CHECK: @n = global i32 0, align 4 |
| 63 | //CHECK: @o = global i32 6, align 4 |
| 64 | //CHECK: @p = constant i32 7, align 4 |
| 65 | |
| 66 | //CHECK: define i32 @foo() #4 { |
| 67 | //CHECK: define i32 @goo() #5 { |
| 68 | //CHECK: declare i32 @zoo(i32*, i32*) #6 |
| 69 | //CHECK: define i32 @hoo() #7 { |
| 70 | |
| 71 | //CHECK: attributes #0 = { "bss-section"="my_bss.1" "data-section"="my_data.1" "rodata-section"="my_rodata.1" } |
| 72 | //CHECK: attributes #1 = { "data-section"="my_data.1" "rodata-section"="my_rodata.1" } |
| 73 | //CHECK: attributes #2 = { "bss-section"="my_bss.2" "rodata-section"="my_rodata.1" } |
| 74 | //CHECK: attributes #3 = { "bss-section"="my_bss.2" "data-section"="my_data.2" "rodata-section"="my_rodata.2" } |
| 75 | //CHECK: attributes #4 = { {{.*"implicit-section-name"="my_text.1".*}} } |
| 76 | //CHECK: attributes #5 = { {{.*"implicit-section-name"="my_text.2".*}} } |
| 77 | //CHECK-NOT: attributes #6 = { {{.*"implicit-section-name".*}} } |
| 78 | //CHECK-NOT: attributes #7 = { {{.*"implicit-section-name".*}} } |