File: unaligned-symbols.c

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 (110 lines) | stat: -rw-r--r-- 4,924 bytes parent folder | download | duplicates (7)
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
// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
// RUN:    | FileCheck %s -check-prefixes=CHECK,ALIGNED

// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
// RUN:    -target-feature -unaligned-symbols | FileCheck %s -check-prefixes=CHECK,ALIGNED

// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
// RUN:    -target-feature +unaligned-symbols | FileCheck %s -check-prefixes=CHECK,UNALIGN


// With -munaligned-symbols, the external and unaligned ("ExtUnal...")
// variable of each test should be treated as unaligned. For the explicitly
// aligned ("ExtExplAlign...") variables and those defined in the translation
// unit ("Aligned..."), the normal ABI alignment of 2 should still be
// in effect.

// ALIGNED: @ExtUnal = external global i8, align 2
// UNALIGN: @ExtUnal = external global i8, align 1
// CHECK:   @ExtExplAlign = external global i8, align 2
// CHECK:   @Aligned = {{(dso_local )?}}global i8 0, align 2
extern unsigned char ExtUnal;
extern unsigned char ExtExplAlign __attribute__((aligned(2)));
unsigned char Aligned;
unsigned char foo0 () {
  return ExtUnal + ExtExplAlign + Aligned;
}

// ALIGNED: @ExtUnal_c2Arr = external global [2 x i8], align 2
// UNALIGN: @ExtUnal_c2Arr = external global [2 x i8], align 1
// CHECK:   @ExtExplAlign_c2Arr = external global [2 x i8], align 2
// CHECK:   @Aligned_c2Arr = {{(dso_local )?}}global [2 x i8] zeroinitializer, align 2
extern unsigned char ExtUnal_c2Arr[2];
extern unsigned char ExtExplAlign_c2Arr[2] __attribute__((aligned(2)));
unsigned char Aligned_c2Arr[2];
unsigned char foo1 () {
  return ExtUnal_c2Arr[0] + ExtExplAlign_c2Arr[0] + Aligned_c2Arr[0];
}

// ALIGNED: @ExtUnal_s1c = external global %struct.s1c, align 2
// UNALIGN: @ExtUnal_s1c = external global %struct.s1c, align 1
// CHECK:   @ExtExplAlign_s1c = external global %struct.s1c, align 2
// CHECK:   @Aligned_s1c = {{(dso_local )?}}global %struct.s1c zeroinitializer, align 2
struct s1c { char c; };
extern struct s1c ExtUnal_s1c;
extern struct s1c ExtExplAlign_s1c __attribute__((aligned(2)));
struct s1c Aligned_s1c;
unsigned char foo2 () {
  return ExtUnal_s1c.c + ExtExplAlign_s1c.c + Aligned_s1c.c;
}

// ALIGNED: @ExtUnal_s2c = external global %struct.s2c, align 2
// UNALIGN: @ExtUnal_s2c = external global %struct.s2c, align 1
// CHECK:   @ExtExplAlign_s2c = external global %struct.s2c, align 2
// CHECK:   @Aligned_s2c = {{(dso_local )?}}global %struct.s2c zeroinitializer, align 2
struct s2c { char c; char c1;};
extern struct s2c ExtUnal_s2c;
extern struct s2c ExtExplAlign_s2c __attribute__((aligned(2)));
struct s2c Aligned_s2c;
unsigned char foo3 () {
  return ExtUnal_s2c.c + ExtExplAlign_s2c.c + Aligned_s2c.c;
}

// ALIGNED: @ExtUnal_s_c2Arr = external global %struct.s_c2Arr, align 2
// UNALIGN: @ExtUnal_s_c2Arr = external global %struct.s_c2Arr, align 1
// CHECK:   @ExtExplAlign_s_c2Arr = external global %struct.s_c2Arr, align 2
// CHECK:   @Aligned_s_c2Arr = {{(dso_local )?}}global %struct.s_c2Arr zeroinitializer, align 2
struct s_c2Arr { char c[2]; };
extern struct s_c2Arr ExtUnal_s_c2Arr;
extern struct s_c2Arr ExtExplAlign_s_c2Arr __attribute__((aligned(2)));
struct s_c2Arr Aligned_s_c2Arr;
unsigned char foo4 () {
  return ExtUnal_s_c2Arr.c[0] + ExtExplAlign_s_c2Arr.c[0] + Aligned_s_c2Arr.c[0];
}

// ALIGNED: @ExtUnal_s_packed = external global %struct.s_packed, align 2
// UNALIGN: @ExtUnal_s_packed = external global %struct.s_packed, align 1
// CHECK:   @ExtExplAlign_s_packed = external global %struct.s_packed, align 2
// CHECK:   @Aligned_s_packed = {{(dso_local )?}}global %struct.s_packed zeroinitializer, align 2
struct s_packed {
    int __attribute__((__packed__)) i;
    char c;
};
extern struct s_packed ExtUnal_s_packed;
extern struct s_packed ExtExplAlign_s_packed __attribute__((aligned(2)));
struct s_packed Aligned_s_packed;
unsigned char foo5 () {
  return ExtUnal_s_packed.c + ExtExplAlign_s_packed.c + Aligned_s_packed.c;
}

// ALIGNED: @ExtUnAl_s_nested = external global [2 x %struct.s_nested], align 2
// UNALIGN: @ExtUnAl_s_nested = external global [2 x %struct.s_nested], align 1
// CHECK:   @ExtExplAlign_s_nested = external global [2 x %struct.s_nested], align 2
// CHECK:   @Aligned_s_nested = {{(dso_local )?}}global [2 x %struct.s_nested] zeroinitializer, align 2
struct s_nested { struct s_c2Arr a[2]; };
extern struct s_nested ExtUnAl_s_nested[2];
extern struct s_nested ExtExplAlign_s_nested[2] __attribute__((aligned(2)));
struct s_nested Aligned_s_nested[2];
unsigned char foo6 () {
  return ExtUnAl_s_nested[0].a[0].c[0] + ExtExplAlign_s_nested[0].a[0].c[0] +
         Aligned_s_nested[0].a[0].c[0];
}

// A weak symbol could be replaced with an unaligned one at link time.
// CHECK-LABEL: foo7
// ALIGNED: load i8, ptr @Weaksym, align 2
// UNALIGN: load i8, ptr @Weaksym, align 1
unsigned char __attribute__((weak)) Weaksym = 0;
unsigned char foo7 () {
  return Weaksym;
}