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 struct __attribute__((aligned(16))) AlignedS
{
51 struct __attribute__((aligned(16))) A
{
54 AlignedS
*getAlignedS() {
55 return (AlignedS
*)m1
;
73 struct __attribute__((aligned(16))) D0
: B0
, B1
{
76 struct __attribute__((aligned(16))) D1
: virtual B0
{
94 struct __attribute__((aligned(16))) D3
: B4
, D2
{
97 struct __attribute__((aligned(16))) D4
: virtual D2
{
100 struct D5
: virtual D0
{
103 return (AlignedS
*)m0
; // expected-warning {{cast from 'char *' to 'AlignedS *'}}
107 struct D6
: virtual D5
{
110 struct D7
: virtual D3
{
113 void test2(int n
, A
*a2
) {
114 __attribute__((aligned(16))) char m
[sizeof(A
) * 2];
115 char(&m_ref
)[sizeof(A
) * 2] = m
;
116 extern char(&m_ref_noinit
)[sizeof(A
) * 2];
117 __attribute__((aligned(16))) char vararray
[10][n
];
120 C t2
= {.m0
= t0
, .m1
= t1
};
121 __attribute__((aligned(16))) char t3
[5][5][5];
122 __attribute__((aligned(16))) char t4
[4][16];
128 __attribute__((aligned(1))) D7 t10
;
132 a
= (A
*)(m
+ sizeof(A
));
133 a
= (A
*)(sizeof(A
) + m
);
134 a
= (A
*)((sizeof(A
) * 2 + m
) - sizeof(A
));
135 a
= (A
*)((sizeof(A
) * 2 + m
) - 1); // expected-warning {{cast from 'char *' to 'A *'}}
136 a
= (A
*)(m
+ 1); // expected-warning {{cast from 'char *' to 'A *'}}
137 a
= (A
*)(1 + m
); // expected-warning {{cast from 'char *' to 'A *'}}
138 a
= (A
*)(m
+ n
); // expected-warning {{cast from 'char *' to 'A *'}}
139 a
= (A
*)&*&m
[sizeof(A
)];
140 a
= (A
*)(0, 0, &m
[sizeof(A
)]);
141 a
= (A
*)&(0, 0, *&m
[sizeof(A
)]);
142 a
= (A
*)&m
[n
]; // expected-warning {{cast from 'char *' to 'A *'}}
144 a
= (A
*)&m_ref_noinit
; // expected-warning {{cast from 'char (*)[64]' to 'A *'}}
145 a
= (A
*)(&vararray
[4][0]); // expected-warning {{cast from 'char *' to 'A *'}}
146 a
= (A
*)(a2
->m0
+ sizeof(A
)); // expected-warning {{cast from 'char *' to 'A *'}}
148 a
= (A
*)(&t2
.m1
); // expected-warning {{cast from 'B0 *' to 'A *'}}
151 a
= (A
*)(&t3
[3][3][0]); // expected-warning {{cast from 'char *' to 'A *'}}
152 a
= (A
*)(&t3
[2][2][4]);
153 a
= (A
*)(&t3
[0][n
][0]); // expected-warning {{cast from 'char *' to 'A *'}}
155 a
= (A
*)&t4
[n
][1]; // expected-warning {{cast from 'char *' to 'A *'}}
158 a
= (A
*)(static_cast<B1
*>(&t5
));
159 a
= (A
*)(&(static_cast<B1
&>(t5
)));
160 a
= (A
*)(static_cast<B0
*>(&t6
)); // expected-warning {{cast from 'B0 *' to 'A *'}}
161 a
= (A
*)(static_cast<B2
*>(&t7
)); // expected-warning {{cast from 'B2 *' to 'A *'}}
162 a
= (A
*)(static_cast<B3
*>(&t7
));
163 a
= (A
*)(static_cast<B2
*>(&t8
)); // expected-warning {{cast from 'B2 *' to 'A *'}}
164 a
= (A
*)(static_cast<B3
*>(&t8
)); // expected-warning {{cast from 'B3 *' to 'A *'}}
165 a
= (A
*)(static_cast<D5
*>(&t9
)); // expected-warning {{cast from 'D5 *' to 'A *'}}
166 a
= (A
*)(static_cast<D3
*>(&t10
)); // expected-warning {{cast from 'D3 *' to 'A *'}}