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