1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wno-unused-value -Wcast-align -verify %s
5 char *a
; short *b
; int *c
;
8 a
= static_cast<char*>(P
);
9 a
= reinterpret_cast<char*>(P
);
10 typedef char *CharPtr
;
13 b
= (short*) P
; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}}
14 b
= reinterpret_cast<short*>(P
);
15 typedef short *ShortPtr
;
16 b
= ShortPtr(P
); // expected-warning {{cast from 'char *' to 'ShortPtr' (aka 'short *') increases required alignment from 1 to 2}}
18 c
= (int*) P
; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}}
19 c
= reinterpret_cast<int*>(P
);
21 c
= IntPtr(P
); // expected-warning {{cast from 'char *' to 'IntPtr' (aka 'int *') increases required alignment from 1 to 4}}
24 // Casts from void* are a special case.
26 char *a
; short *b
; int *c
;
29 a
= static_cast<char*>(P
);
30 a
= reinterpret_cast<char*>(P
);
31 typedef char *CharPtr
;
35 b
= static_cast<short*>(P
);
36 b
= reinterpret_cast<short*>(P
);
37 typedef short *ShortPtr
;
41 c
= static_cast<int*>(P
);
42 c
= reinterpret_cast<int*>(P
);
47 template <class A
> void DependentAlign() {
48 alignas(A
) int lut
[]{};
49 (long *)lut
; // expected-warning {{cast from 'int *' to 'long *'}}
52 struct __attribute__((aligned(16))) AlignedS
{
56 struct __attribute__((aligned(16))) A
{
59 AlignedS
*getAlignedS() {
60 return (AlignedS
*)m1
;
78 struct __attribute__((aligned(16))) D0
: B0
, B1
{
81 struct __attribute__((aligned(16))) D1
: virtual B0
{
99 struct __attribute__((aligned(16))) D3
: B4
, D2
{
102 struct __attribute__((aligned(16))) D4
: virtual D2
{
105 struct D5
: virtual D0
{
108 return (AlignedS
*)m0
; // expected-warning {{cast from 'char *' to 'AlignedS *'}}
112 struct D6
: virtual D5
{
115 struct D7
: virtual D3
{
118 void test2(int n
, A
*a2
) {
119 __attribute__((aligned(16))) char m
[sizeof(A
) * 2];
120 char(&m_ref
)[sizeof(A
) * 2] = m
;
121 extern char(&m_ref_noinit
)[sizeof(A
) * 2];
122 __attribute__((aligned(16))) char vararray
[10][n
];
125 C t2
= {.m0
= t0
, .m1
= t1
};
126 __attribute__((aligned(16))) char t3
[5][5][5];
127 __attribute__((aligned(16))) char t4
[4][16];
133 __attribute__((aligned(1))) D7 t10
;
137 a
= (A
*)(m
+ sizeof(A
));
138 a
= (A
*)(sizeof(A
) + m
);
139 a
= (A
*)((sizeof(A
) * 2 + m
) - sizeof(A
));
140 a
= (A
*)((sizeof(A
) * 2 + m
) - 1); // expected-warning {{cast from 'char *' to 'A *'}}
141 a
= (A
*)(m
+ 1); // expected-warning {{cast from 'char *' to 'A *'}}
142 a
= (A
*)(1 + m
); // expected-warning {{cast from 'char *' to 'A *'}}
143 a
= (A
*)(m
+ n
); // expected-warning {{cast from 'char *' to 'A *'}}
144 a
= (A
*)&*&m
[sizeof(A
)];
145 a
= (A
*)(0, 0, &m
[sizeof(A
)]);
146 a
= (A
*)&(0, 0, *&m
[sizeof(A
)]);
147 a
= (A
*)&m
[n
]; // expected-warning {{cast from 'char *' to 'A *'}}
149 a
= (A
*)&m_ref_noinit
; // expected-warning {{cast from 'char (*)[64]' to 'A *'}}
150 a
= (A
*)(&vararray
[4][0]); // expected-warning {{cast from 'char *' to 'A *'}}
151 a
= (A
*)(a2
->m0
+ sizeof(A
)); // expected-warning {{cast from 'char *' to 'A *'}}
153 a
= (A
*)(&t2
.m1
); // expected-warning {{cast from 'B0 *' to 'A *'}}
156 a
= (A
*)(&t3
[3][3][0]); // expected-warning {{cast from 'char *' to 'A *'}}
157 a
= (A
*)(&t3
[2][2][4]);
158 a
= (A
*)(&t3
[0][n
][0]); // expected-warning {{cast from 'char *' to 'A *'}}
160 a
= (A
*)&t4
[n
][1]; // expected-warning {{cast from 'char *' to 'A *'}}
163 a
= (A
*)(static_cast<B1
*>(&t5
));
164 a
= (A
*)(&(static_cast<B1
&>(t5
)));
165 a
= (A
*)(static_cast<B0
*>(&t6
)); // expected-warning {{cast from 'B0 *' to 'A *'}}
166 a
= (A
*)(static_cast<B2
*>(&t7
)); // expected-warning {{cast from 'B2 *' to 'A *'}}
167 a
= (A
*)(static_cast<B3
*>(&t7
));
168 a
= (A
*)(static_cast<B2
*>(&t8
)); // expected-warning {{cast from 'B2 *' to 'A *'}}
169 a
= (A
*)(static_cast<B3
*>(&t8
)); // expected-warning {{cast from 'B3 *' to 'A *'}}
170 a
= (A
*)(static_cast<D5
*>(&t9
)); // expected-warning {{cast from 'D5 *' to 'A *'}}
171 a
= (A
*)(static_cast<D3
*>(&t10
)); // expected-warning {{cast from 'D3 *' to 'A *'}}