1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s 2 3 // Simple casts. 4 void 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. 11 void 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. 31 struct __attribute__((aligned(16))) A { 32 char buffer[16]; 33 }; 34 void 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. 39 void test3(char *P) { 40 struct B *b = (struct B*) P; 41 } 42