1 // RUN: %clang_cc1 %s -triple=armv7-none-none-eabi -verify -Wunaligned-access -S -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.
15 // Packed-Unpacked Tests (No Pragma)
22 struct __attribute__((packed
)) U1
{
24 T1 b
; // expected-warning {{field b within 'U1' is less aligned than 'T1' and is usually due to 'U1' being packed, which can lead to unaligned accesses}}
28 struct __attribute__((packed
)) U2
{
30 T1 b
__attribute__((aligned(4)));
34 struct __attribute__((packed
)) U3
{
41 struct __attribute__((packed
)) U4
{
46 struct __attribute__((aligned(4), packed
)) U5
{
48 T1 b
; // expected-warning {{field b within 'U5' is less aligned than 'T1' and is usually due to 'U5' being packed, which can lead to unaligned accesses}}
52 struct __attribute__((aligned(4), packed
)) U6
{
59 // Packed-Unpacked Tests with Pragma
63 struct __attribute__((packed
)) U7
{
65 T1 b
; // expected-warning {{field b within 'U7' is less aligned than 'T1' and is usually due to 'U7' being packed, which can lead to unaligned accesses}}
69 struct __attribute__((packed
)) U8
{
71 T1 b
__attribute__((aligned(4))); // expected-warning {{field b within 'U8' is less aligned than 'T1' and is usually due to 'U8' being packed, which can lead to unaligned accesses}}
75 struct __attribute__((aligned(4))) U9
{
77 T1 b
; // expected-warning {{field b within 'U9' is less aligned than 'T1' and is usually due to 'U9' being packed, which can lead to unaligned accesses}}
83 T1 b
; // expected-warning {{field b within 'U10' is less aligned than 'T1' and is usually due to 'U10' being packed, which can lead to unaligned accesses}}
89 // Packed-Packed Tests
91 struct __attribute__((packed
)) T2
{
96 struct __attribute__((packed
)) U11
{
102 #pragma pack(push, 1)
110 // Unpacked-Packed Tests
120 T2 b
__attribute__((aligned(4)));
124 // Unpacked-Unpacked Test
137 // Packed-Packed-Unpacked Test (No pragma)
139 struct __attribute__((packed
)) A1
{
141 T1 b
; // expected-warning {{field b within 'A1' is less aligned than 'T1' and is usually due to 'A1' being packed, which can lead to unaligned accesses}}
144 struct __attribute__((packed
)) U16
{
150 struct __attribute__((packed
)) A2
{
152 T1 b
__attribute__((aligned(4)));
155 struct __attribute__((packed
)) U17
{
157 A2 b
; // expected-warning {{field b within 'U17' is less aligned than 'A2' and is usually due to 'U17' being packed, which can lead to unaligned accesses}}
161 // Packed-Unpacked-Packed tests
168 struct __attribute__((packed
)) U18
{
180 #pragma pack(push, 1)
183 A4 b
; // expected-warning {{field b within 'U19' is less aligned than 'A4' and is usually due to 'U19' being packed, which can lead to unaligned accesses}}
188 // Packed-Unpacked-Unpacked tests
195 struct __attribute__((packed
)) U20
{
197 A5 b
; // expected-warning {{field b within 'U20' is less aligned than 'A5' and is usually due to 'U20' being packed, which can lead to unaligned accesses}}
206 #pragma pack(push, 1)
209 A6 b
; // expected-warning {{field b within 'U21' is less aligned than 'A6' and is usually due to 'U21' being packed, which can lead to unaligned accesses}}
214 // Unpacked-Packed-Packed test
216 struct __attribute__((packed
)) A7
{
227 // Unpacked-Packed-Unpacked tests
229 struct __attribute__((packed
)) A8
{
231 T1 b
; // expected-warning {{field b within 'A8' is less aligned than 'T1' and is usually due to 'A8' being packed, which can lead to unaligned accesses}}
240 struct __attribute__((packed
)) A9
{
242 T1 b
__attribute__((aligned(4)));