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