213 lines · c
1// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify -Wvla2 3int array[(long)(char *)0]; // expected-warning {{variable length array used}} \4 // expected-warning {{variable length array folded to constant array as an extension}} \5 // expected-note {{this conversion is not allowed in a constant expression}}6 7typedef struct { unsigned long bits[(((1) + (64) - 1) / (64))]; } cpumask_t;8cpumask_t x;9void foo(void) {10 (void)x;11}12void bar(void) {13 char* a;14 double b;15 b = (double)a; // expected-error {{pointer cannot be cast to type}}16 a = (char*)b; // expected-error {{cannot be cast to a pointer type}}17}18 19long bar1(long *next) {20 return (long)(*next)++; 21}22 23typedef _Bool Bool;24typedef int Int;25typedef long Long;26typedef float Float;27typedef double Double;28typedef _Complex int CInt;29typedef _Complex long CLong;30typedef _Complex float CFloat;31typedef _Complex double CDouble;32typedef void *VoidPtr;33typedef char *CharPtr;34 35void testBool(Bool v) {36 (void) (Bool) v;37 (void) (Int) v;38 (void) (Long) v;39 (void) (Float) v;40 (void) (Double) v;41 (void) (CInt) v;42 (void) (CLong) v;43 (void) (CFloat) v;44 (void) (CDouble) v;45 (void) (VoidPtr) v;46 (void) (CharPtr) v;47}48 49void testInt(Int v) {50 (void) (Bool) v;51 (void) (Int) v;52 (void) (Long) v;53 (void) (Float) v;54 (void) (Double) v;55 (void) (CInt) v;56 (void) (CLong) v;57 (void) (CFloat) v;58 (void) (CDouble) v;59 (void) (VoidPtr) v; // expected-warning{{cast to 'VoidPtr' (aka 'void *') from smaller integer type 'Int' (aka 'int')}}60 (void) (CharPtr) v; // expected-warning{{cast to 'CharPtr' (aka 'char *') from smaller integer type 'Int' (aka 'int')}}61 62 // Test that casts to void* can be controlled separately63 // from other -Wint-to-pointer-cast warnings.64#pragma clang diagnostic push65#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast"66 (void) (VoidPtr) v; // no-warning67 (void) (CharPtr) v; // expected-warning{{cast to 'CharPtr' (aka 'char *') from smaller integer type 'Int' (aka 'int')}}68#pragma clang diagnostic pop69}70 71void testLong(Long v) {72 (void) (Bool) v;73 (void) (Int) v;74 (void) (Long) v;75 (void) (Float) v;76 (void) (Double) v;77 (void) (CInt) v;78 (void) (CLong) v;79 (void) (CFloat) v;80 (void) (CDouble) v;81 (void) (VoidPtr) v;82 (void) (CharPtr) v;83}84 85void testFloat(Float v) {86 (void) (Bool) v;87 (void) (Int) v;88 (void) (Long) v;89 (void) (Float) v;90 (void) (Double) v;91 (void) (CInt) v;92 (void) (CLong) v;93 (void) (CFloat) v;94 (void) (CDouble) v;95}96 97void testDouble(Double v) {98 (void) (Bool) v;99 (void) (Int) v;100 (void) (Long) v;101 (void) (Float) v;102 (void) (Double) v;103 (void) (CInt) v;104 (void) (CLong) v;105 (void) (CFloat) v;106 (void) (CDouble) v;107}108 109void testCI(CInt v) {110 (void) (Bool) v;111 (void) (Int) v;112 (void) (Long) v;113 (void) (Float) v;114 (void) (Double) v;115 (void) (CInt) v;116 (void) (CLong) v;117 (void) (CFloat) v;118 (void) (CDouble) v;119}120 121void testCLong(CLong v) {122 (void) (Bool) v;123 (void) (Int) v;124 (void) (Long) v;125 (void) (Float) v;126 (void) (Double) v;127 (void) (CInt) v;128 (void) (CLong) v;129 (void) (CFloat) v;130 (void) (CDouble) v;131}132 133void testCFloat(CFloat v) {134 (void) (Bool) v;135 (void) (Int) v;136 (void) (Long) v;137 (void) (Float) v;138 (void) (Double) v;139 (void) (CInt) v;140 (void) (CLong) v;141 (void) (CFloat) v;142 (void) (CDouble) v;143}144 145void testCDouble(CDouble v) {146 (void) (Bool) v;147 (void) (Int) v;148 (void) (Long) v;149 (void) (Float) v;150 (void) (Double) v;151 (void) (CInt) v;152 (void) (CLong) v;153 (void) (CFloat) v;154 (void) (CDouble) v;155}156 157void testVoidPtr(VoidPtr v) {158 (void)(Bool) v;159 (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'VoidPtr' (aka 'void *')}}160 (void) (Long) v;161 (void) (VoidPtr) v;162 (void) (CharPtr) v;163 // Test that casts to void* can be controlled separately164 // from other -Wpointer-to-int-cast warnings.165#pragma clang diagnostic push166#pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"167 (void)(Int) v; // no-warning168#pragma clang diagnostic pop169}170 171void testCharPtr(CharPtr v) {172 (void)(Bool) v;173 (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}174 (void) (Long) v;175 (void) (VoidPtr) v;176 (void) (CharPtr) v;177 // Test that casts to void* can be controlled separately178 // from other -Wpointer-to-int-cast warnings.179#pragma clang diagnostic push180#pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"181 (void)(Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}182#pragma clang diagnostic pop183}184 185typedef enum { x_a, x_b } X;186void *intToPointerCast2(X x) {187 return (void*)x;188}189 190void *intToPointerCast3(void) {191 return (void*)(1 + 3);192}193 194void voidPointerToEnumCast(VoidPtr v) {195 (void)(X) v; // expected-warning{{cast to smaller integer type 'X' from 'VoidPtr' (aka 'void *')}}196 // Test that casts to void* can be controlled separately197 // from other -Wpointer-to-enum-cast warnings.198#pragma clang diagnostic push199#pragma clang diagnostic ignored "-Wvoid-pointer-to-enum-cast"200 (void)(X) v; // no-warning201#pragma clang diagnostic pop202}203 204void pointerToEnumCast(CharPtr v) {205 (void)(X) v; // expected-warning{{cast to smaller integer type 'X' from 'CharPtr' (aka 'char *')}}206 // Test that casts to void* can be controlled separately207 // from other -Wpointer-to-enum-cast warnings.208#pragma clang diagnostic push209#pragma clang diagnostic ignored "-Wvoid-pointer-to-enum-cast"210 (void)(X) v; // expected-warning{{cast to smaller integer type 'X' from 'CharPtr' (aka 'char *')}}211#pragma clang diagnostic pop212}213