1 // RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access -emit-llvm -o %t
2 // REQUIRES: arm-registered-target
4 // This test suite tests the warning triggered by the -Wunaligned-access option.
5 // The warning occurs when a struct or other type of record contains a field
6 // that is itself a record. The outer record must be a packed structure, while
7 // while the inner record must be unpacked. This is the fundamental condition
8 // for the warning to be triggered. Some of these tests may have three layers.
10 // The command line option -fsyntax-only is not used as Clang needs to be
11 // forced to layout the structs used in this test.
12 // The triple in the command line above is used for the assumptions about
13 // size and alignment of types.
21 struct __attribute__((packed
)) U1
{
23 struct T1 b
; // expected-warning {{field b within 'struct U1' is less aligned than 'struct T1' and is usually due to 'struct U1' being packed, which can lead to unaligned accesses}}
27 struct __attribute__((packed
)) U2
{
29 struct T1 b
__attribute__((aligned(2))); // expected-warning {{field b within 'struct U2' is less aligned than 'struct T1' and is usually due to 'struct U2' being packed, which can lead to unaligned accesses}}
33 struct __attribute__((packed
)) U3
{
35 struct T1 b
__attribute__((aligned(4)));
39 struct __attribute__((aligned(2))) U4
{
54 struct T1 c
__attribute__((aligned(2)));
57 struct __attribute__((packed
)) U7
{
61 struct T1 d
; // expected-warning {{field d within 'struct U7' is less aligned than 'struct T1' and is usually due to 'struct U7' being packed, which can lead to unaligned accesses}}
71 struct __attribute__((packed
)) U9
{
75 struct T1 d
__attribute__((aligned(4)));
78 struct __attribute__((packed
)) U10
{
82 struct T1 d
__attribute__((aligned(2))); // expected-warning {{field d within 'struct U10' is less aligned than 'struct T1' and is usually due to 'struct U10' being packed, which can lead to unaligned accesses}}
85 struct __attribute__((aligned(2))) U11
{
97 struct T1 b
; // expected-warning {{field b within 'struct U12' is less aligned than 'struct T1' and is usually due to 'struct U12' being packed, which can lead to unaligned accesses}}
101 struct __attribute__((packed
)) U13
{
103 struct T1 b
; // expected-warning {{field b within 'struct U13' is less aligned than 'struct T1' and is usually due to 'struct U13' being packed, which can lead to unaligned accesses}}
107 struct __attribute__((packed
)) U14
{
109 struct T1 b
__attribute__((aligned(4))); // expected-warning {{field b within 'struct U14' is less aligned than 'struct T1' and is usually due to 'struct U14' being packed, which can lead to unaligned accesses}}
113 struct __attribute__((aligned(2))) U15
{
115 struct T1 b
; // expected-warning {{field b within 'struct U15' is less aligned than 'struct T1' and is usually due to 'struct U15' being packed, which can lead to unaligned accesses}}
130 struct T1 d
__attribute__((aligned(4)));
133 struct __attribute__((packed
)) U18
{
136 struct T1 c
__attribute__((aligned(4))); // expected-warning {{field c within 'struct U18' is less aligned than 'struct T1' and is usually due to 'struct U18' being packed, which can lead to unaligned accesses}}
139 struct __attribute__((aligned(4))) U19
{
141 struct T1 b
; // expected-warning {{field b within 'struct U19' is less aligned than 'struct T1' and is usually due to 'struct U19' being packed, which can lead to unaligned accesses}}
145 struct __attribute__((aligned(4))) U20
{
154 struct T1 d
; // expected-warning {{field d within 'struct U21' is less aligned than 'struct T1' and is usually due to 'struct U21' being packed, which can lead to unaligned accesses}}
160 struct T1 d
__attribute__((aligned(4))); // expected-warning {{field d within 'struct U22' is less aligned than 'struct T1' and is usually due to 'struct U22' being packed, which can lead to unaligned accesses}}
166 #pragma pack(push, 2)
168 struct __attribute__((packed
)) U23
{
170 struct T1 b
; // expected-warning {{field b within 'struct U23' is less aligned than 'struct T1' and is usually due to 'struct U23' being packed, which can lead to unaligned accesses}}
176 struct T1 b
; // expected-warning {{field b within 'struct U24' is less aligned than 'struct T1' and is usually due to 'struct U24' being packed, which can lead to unaligned accesses}}
198 struct __attribute__((packed
)) T2
{
200 struct T1 b
; // expected-warning {{field b within 'struct T2' is less aligned than 'struct T1' and is usually due to 'struct T2' being packed, which can lead to unaligned accesses}}
208 struct __attribute__((packed
)) U27
{
227 struct __attribute__((packed
)) U30
{
229 struct T3 b
; // expected-warning {{field b within 'struct U30' is less aligned than 'struct T3' and is usually due to 'struct U30' being packed, which can lead to unaligned accesses}}
233 struct __attribute__((packed
)) U31
{
235 struct T2 b
__attribute__((aligned(4)));
238 struct __attribute__((packed
)) U32
{
246 struct __attribute__((packed
)) U33
{
251 struct T2 e
__attribute__((aligned(4)));
254 struct __attribute__((packed
)) U34
{
256 struct T1 b
__attribute__((packed
)); // expected-warning {{field b within 'struct U34' is less aligned than 'struct T1' and is usually due to 'struct U34' being packed, which can lead to unaligned accesses}}
260 struct __attribute__((packed
)) U35
{
265 } d
; // expected-warning {{field d within 'struct U35' is less aligned than 'struct T4' and is usually due to 'struct U35' being packed, which can lead to unaligned accesses}}
270 #pragma pack(push, 1)
273 struct T1 b
; // expected-warning {{field b within 'struct T5' is less aligned than 'struct T1' and is usually due to 'struct T5' being packed, which can lead to unaligned accesses}}
277 #pragma pack(push, 1)
286 struct T3 b
; // expected-warning {{field b within 'struct U37' is less aligned than 'struct T3' and is usually due to 'struct U37' being packed, which can lead to unaligned accesses}}
292 struct T5 b
__attribute__((aligned(4)));
296 #pragma pack(push, 1)
298 #pragma pack(push, 4)
310 struct __attribute__((packed
)) A1
{
312 struct T1 b
; // expected-warning {{field b within 'struct A1' is less aligned than 'struct T1' and is usually due to 'struct A1' being packed, which can lead to unaligned accesses}}
320 struct __attribute__((packed
)) A3
{
322 struct T1 b
__attribute__((aligned(4)));
325 #pragma pack(push, 1)
328 struct T1 b
; // expected-warning {{field b within 'struct A4' is less aligned than 'struct T1' and is usually due to 'struct A4' being packed, which can lead to unaligned accesses}}
333 struct T1 b
__attribute__((aligned(4))); // expected-warning {{field b within 'struct A5' is less aligned than 'struct T1' and is usually due to 'struct A5' being packed, which can lead to unaligned accesses}}
337 struct __attribute__((packed
)) A6
{
343 struct T1 b
__attribute__((packed
));
360 struct T2 b
__attribute__((aligned(4)));
363 struct __attribute__((packed
)) A11
{
368 struct __attribute__((packed
)) U40
{
374 struct __attribute__((packed
)) U41
{
376 struct A3 b
; // expected-warning {{field b within 'struct U41' is less aligned than 'struct A3' and is usually due to 'struct U41' being packed, which can lead to unaligned accesses}}
380 #pragma pack(push, 1)
388 struct __attribute__((packed
)) U43
{
394 struct __attribute__((packed
)) U44
{
396 struct A10 b
; // expected-warning {{field b within 'struct U44' is less aligned than 'struct A10' and is usually due to 'struct U44' being packed, which can lead to unaligned accesses}}
400 #pragma pack(push, 1)
404 struct A10 b
; // expected-warning {{field b within 'struct U45' is less aligned than 'struct A10' and is usually due to 'struct U45' being packed, which can lead to unaligned accesses}}
410 struct __attribute__((packed
)) U46
{
412 struct A2 b
; // expected-warning {{field b within 'struct U46' is less aligned than 'struct A2' and is usually due to 'struct U46' being packed, which can lead to unaligned accesses}}
416 struct __attribute__((packed
)) U47
{
418 struct A8 b
; // expected-warning {{field b within 'struct U47' is less aligned than 'struct A8' and is usually due to 'struct U47' being packed, which can lead to unaligned accesses}}
422 #pragma pack(push, 1)
425 struct A8 b
; // expected-warning {{field b within 'struct U48' is less aligned than 'struct A8' and is usually due to 'struct U48' being packed, which can lead to unaligned accesses}}
448 struct __attribute__((packed
)) U52
{