| 1 |
// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \ |
| 2 |
// RUN: | FileCheck %s -check-prefixes=CHECK,ALIGNED |
| 3 |
|
| 4 |
// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \ |
| 5 |
// RUN: -target-feature -unaligned-symbols | FileCheck %s -check-prefixes=CHECK,ALIGNED |
| 6 |
|
| 7 |
// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \ |
| 8 |
// RUN: -target-feature +unaligned-symbols | FileCheck %s -check-prefixes=CHECK,UNALIGN |
| 9 |
|
| 10 |
|
| 11 |
// With -munaligned-symbols, the external and unaligned ("ExtUnal...") |
| 12 |
// variable of each test should be treated as unaligned. For the explicitly |
| 13 |
// aligned ("ExtExplAlign...") variables and those defined in the translation |
| 14 |
// unit ("Aligned..."), the normal ABI alignment of 2 should still be |
| 15 |
// in effect. |
| 16 |
|
| 17 |
// ALIGNED: @ExtUnal = external global i8, align 2 |
| 18 |
// UNALIGN: @ExtUnal = external global i8, align 1 |
| 19 |
// CHECK: @ExtExplAlign = external global i8, align 2 |
| 20 |
// CHECK: @Aligned = {{(dso_local )?}}global i8 0, align 2 |
| 21 |
extern unsigned char ExtUnal; |
| 22 |
extern unsigned char ExtExplAlign __attribute__((aligned(2))); |
| 23 |
unsigned char Aligned; |
| 24 |
unsigned char foo0 () { |
| 25 |
return ExtUnal + ExtExplAlign + Aligned; |
| 26 |
} |
| 27 |
|
| 28 |
// ALIGNED: @ExtUnal_c2Arr = external global [2 x i8], align 2 |
| 29 |
// UNALIGN: @ExtUnal_c2Arr = external global [2 x i8], align 1 |
| 30 |
// CHECK: @ExtExplAlign_c2Arr = external global [2 x i8], align 2 |
| 31 |
// CHECK: @Aligned_c2Arr = {{(dso_local )?}}global [2 x i8] zeroinitializer, align 2 |
| 32 |
extern unsigned char ExtUnal_c2Arr[2]; |
| 33 |
extern unsigned char ExtExplAlign_c2Arr[2] __attribute__((aligned(2))); |
| 34 |
unsigned char Aligned_c2Arr[2]; |
| 35 |
unsigned char foo1 () { |
| 36 |
return ExtUnal_c2Arr[0] + ExtExplAlign_c2Arr[0] + Aligned_c2Arr[0]; |
| 37 |
} |
| 38 |
|
| 39 |
// ALIGNED: @ExtUnal_s1c = external global %struct.s1c, align 2 |
| 40 |
// UNALIGN: @ExtUnal_s1c = external global %struct.s1c, align 1 |
| 41 |
// CHECK: @ExtExplAlign_s1c = external global %struct.s1c, align 2 |
| 42 |
// CHECK: @Aligned_s1c = {{(dso_local )?}}global %struct.s1c zeroinitializer, align 2 |
| 43 |
struct s1c { char c; }; |
| 44 |
extern struct s1c ExtUnal_s1c; |
| 45 |
extern struct s1c ExtExplAlign_s1c __attribute__((aligned(2))); |
| 46 |
struct s1c Aligned_s1c; |
| 47 |
unsigned char foo2 () { |
| 48 |
return ExtUnal_s1c.c + ExtExplAlign_s1c.c + Aligned_s1c.c; |
| 49 |
} |
| 50 |
|
| 51 |
// ALIGNED: @ExtUnal_s2c = external global %struct.s2c, align 2 |
| 52 |
// UNALIGN: @ExtUnal_s2c = external global %struct.s2c, align 1 |
| 53 |
// CHECK: @ExtExplAlign_s2c = external global %struct.s2c, align 2 |
| 54 |
// CHECK: @Aligned_s2c = {{(dso_local )?}}global %struct.s2c zeroinitializer, align 2 |
| 55 |
struct s2c { char c; char c1;}; |
| 56 |
extern struct s2c ExtUnal_s2c; |
| 57 |
extern struct s2c ExtExplAlign_s2c __attribute__((aligned(2))); |
| 58 |
struct s2c Aligned_s2c; |
| 59 |
unsigned char foo3 () { |
| 60 |
return ExtUnal_s2c.c + ExtExplAlign_s2c.c + Aligned_s2c.c; |
| 61 |
} |
| 62 |
|
| 63 |
// ALIGNED: @ExtUnal_s_c2Arr = external global %struct.s_c2Arr, align 2 |
| 64 |
// UNALIGN: @ExtUnal_s_c2Arr = external global %struct.s_c2Arr, align 1 |
| 65 |
// CHECK: @ExtExplAlign_s_c2Arr = external global %struct.s_c2Arr, align 2 |
| 66 |
// CHECK: @Aligned_s_c2Arr = {{(dso_local )?}}global %struct.s_c2Arr zeroinitializer, align 2 |
| 67 |
struct s_c2Arr { char c[2]; }; |
| 68 |
extern struct s_c2Arr ExtUnal_s_c2Arr; |
| 69 |
extern struct s_c2Arr ExtExplAlign_s_c2Arr __attribute__((aligned(2))); |
| 70 |
struct s_c2Arr Aligned_s_c2Arr; |
| 71 |
unsigned char foo4 () { |
| 72 |
return ExtUnal_s_c2Arr.c[0] + ExtExplAlign_s_c2Arr.c[0] + Aligned_s_c2Arr.c[0]; |
| 73 |
} |
| 74 |
|
| 75 |
// ALIGNED: @ExtUnal_s_packed = external global %struct.s_packed, align 2 |
| 76 |
// UNALIGN: @ExtUnal_s_packed = external global %struct.s_packed, align 1 |
| 77 |
// CHECK: @ExtExplAlign_s_packed = external global %struct.s_packed, align 2 |
| 78 |
// CHECK: @Aligned_s_packed = {{(dso_local )?}}global %struct.s_packed zeroinitializer, align 2 |
| 79 |
struct s_packed { |
| 80 |
int __attribute__((__packed__)) i; |
| 81 |
char c; |
| 82 |
}; |
| 83 |
extern struct s_packed ExtUnal_s_packed; |
| 84 |
extern struct s_packed ExtExplAlign_s_packed __attribute__((aligned(2))); |
| 85 |
struct s_packed Aligned_s_packed; |
| 86 |
unsigned char foo5 () { |
| 87 |
return ExtUnal_s_packed.c + ExtExplAlign_s_packed.c + Aligned_s_packed.c; |
| 88 |
} |
| 89 |
|
| 90 |
// ALIGNED: @ExtUnAl_s_nested = external global [2 x %struct.s_nested], align 2 |
| 91 |
// UNALIGN: @ExtUnAl_s_nested = external global [2 x %struct.s_nested], align 1 |
| 92 |
// CHECK: @ExtExplAlign_s_nested = external global [2 x %struct.s_nested], align 2 |
| 93 |
// CHECK: @Aligned_s_nested = {{(dso_local )?}}global [2 x %struct.s_nested] zeroinitializer, align 2 |
| 94 |
struct s_nested { struct s_c2Arr a[2]; }; |
| 95 |
extern struct s_nested ExtUnAl_s_nested[2]; |
| 96 |
extern struct s_nested ExtExplAlign_s_nested[2] __attribute__((aligned(2))); |
| 97 |
struct s_nested Aligned_s_nested[2]; |
| 98 |
unsigned char foo6 () { |
| 99 |
return ExtUnAl_s_nested[0].a[0].c[0] + ExtExplAlign_s_nested[0].a[0].c[0] + |
| 100 |
Aligned_s_nested[0].a[0].c[0]; |
| 101 |
} |
| 102 |
|
| 103 |
// A weak symbol could be replaced with an unaligned one at link time. |
| 104 |
// CHECK-LABEL: foo7 |
| 105 |
// ALIGNED: load i8, ptr @Weaksym, align 2 |
| 106 |
// UNALIGN: load i8, ptr @Weaksym, align 1 |
| 107 |
unsigned char __attribute__((weak)) Weaksym = 0; |
| 108 |
unsigned char foo7 () { |
| 109 |
return Weaksym; |
| 110 |
} |