blob: 93352c253a2e753c996d811c5f422612679db499 [file] [log] [blame]
John McCallb7f4ffe2010-08-12 21:44:57 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s
2
3// Simple casts.
4void test0(char *P) {
5 char *a = (char*) P;
6 short *b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}}
7 int *c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}}
8}
9
10// Casts from void* are a special case.
11void test1(void *P) {
12 char *a = (char*) P;
13 short *b = (short*) P;
14 int *c = (int*) P;
15
16 const volatile void *P2 = P;
17 char *d = (char*) P2;
18 short *e = (short*) P2;
19 int *f = (int*) P2;
20
21 const char *g = (const char*) P2;
22 const short *h = (const short*) P2;
23 const int *i = (const int*) P2;
24
25 const volatile char *j = (const volatile char*) P2;
26 const volatile short *k = (const volatile short*) P2;
27 const volatile int *l = (const volatile int*) P2;
28}
29
30// Aligned struct.
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +000031__attribute__((aligned(16))) struct A {
John McCallb7f4ffe2010-08-12 21:44:57 +000032 char buffer[16];
33};
34void test2(char *P) {
35 struct A *a = (struct A*) P; // expected-warning {{cast from 'char *' to 'struct A *' increases required alignment from 1 to 16}}
36}
37
38// Incomplete type.
39void test3(char *P) {
40 struct B *b = (struct B*) P;
41}