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