John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 1 | // Force x86-64 because some of our heuristics are actually based |
| 2 | // on integer sizes. |
| 3 | |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 4 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s |
John McCall | b13c87f | 2009-11-05 09:23:39 +0000 | [diff] [blame] | 5 | |
| 6 | int test0(long a, unsigned long b) { |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 7 | enum EnumA {A}; |
| 8 | enum EnumB {B}; |
| 9 | enum EnumC {C = 0x10000}; |
| 10 | return |
| 11 | // (a,b) |
| 12 | (a == (unsigned long) b) + // expected-warning {{comparison of integers of different signs}} |
| 13 | (a == (unsigned int) b) + |
| 14 | (a == (unsigned short) b) + |
| 15 | (a == (unsigned char) b) + |
| 16 | ((long) a == b) + // expected-warning {{comparison of integers of different signs}} |
| 17 | ((int) a == b) + // expected-warning {{comparison of integers of different signs}} |
| 18 | ((short) a == b) + // expected-warning {{comparison of integers of different signs}} |
| 19 | ((signed char) a == b) + // expected-warning {{comparison of integers of different signs}} |
| 20 | ((long) a == (unsigned long) b) + // expected-warning {{comparison of integers of different signs}} |
| 21 | ((int) a == (unsigned int) b) + // expected-warning {{comparison of integers of different signs}} |
John McCall | 323ed74 | 2010-05-06 08:58:33 +0000 | [diff] [blame] | 22 | ((short) a == (unsigned short) b) + |
| 23 | ((signed char) a == (unsigned char) b) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 24 | (a < (unsigned long) b) + // expected-warning {{comparison of integers of different signs}} |
| 25 | (a < (unsigned int) b) + |
| 26 | (a < (unsigned short) b) + |
| 27 | (a < (unsigned char) b) + |
| 28 | ((long) a < b) + // expected-warning {{comparison of integers of different signs}} |
| 29 | ((int) a < b) + // expected-warning {{comparison of integers of different signs}} |
| 30 | ((short) a < b) + // expected-warning {{comparison of integers of different signs}} |
| 31 | ((signed char) a < b) + // expected-warning {{comparison of integers of different signs}} |
| 32 | ((long) a < (unsigned long) b) + // expected-warning {{comparison of integers of different signs}} |
| 33 | ((int) a < (unsigned int) b) + // expected-warning {{comparison of integers of different signs}} |
John McCall | 323ed74 | 2010-05-06 08:58:33 +0000 | [diff] [blame] | 34 | ((short) a < (unsigned short) b) + |
| 35 | ((signed char) a < (unsigned char) b) + |
John McCall | b13c87f | 2009-11-05 09:23:39 +0000 | [diff] [blame] | 36 | |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 37 | // (A,b) |
| 38 | (A == (unsigned long) b) + |
| 39 | (A == (unsigned int) b) + |
| 40 | (A == (unsigned short) b) + |
| 41 | (A == (unsigned char) b) + |
| 42 | ((long) A == b) + |
| 43 | ((int) A == b) + |
| 44 | ((short) A == b) + |
| 45 | ((signed char) A == b) + |
| 46 | ((long) A == (unsigned long) b) + |
| 47 | ((int) A == (unsigned int) b) + |
| 48 | ((short) A == (unsigned short) b) + |
| 49 | ((signed char) A == (unsigned char) b) + |
| 50 | (A < (unsigned long) b) + |
| 51 | (A < (unsigned int) b) + |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 52 | (A < (unsigned short) b) + |
| 53 | (A < (unsigned char) b) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 54 | ((long) A < b) + |
| 55 | ((int) A < b) + |
| 56 | ((short) A < b) + |
| 57 | ((signed char) A < b) + |
| 58 | ((long) A < (unsigned long) b) + |
| 59 | ((int) A < (unsigned int) b) + |
| 60 | ((short) A < (unsigned short) b) + |
| 61 | ((signed char) A < (unsigned char) b) + |
| 62 | |
| 63 | // (a,B) |
| 64 | (a == (unsigned long) B) + |
| 65 | (a == (unsigned int) B) + |
| 66 | (a == (unsigned short) B) + |
| 67 | (a == (unsigned char) B) + |
| 68 | ((long) a == B) + |
| 69 | ((int) a == B) + |
| 70 | ((short) a == B) + |
| 71 | ((signed char) a == B) + |
| 72 | ((long) a == (unsigned long) B) + |
| 73 | ((int) a == (unsigned int) B) + |
| 74 | ((short) a == (unsigned short) B) + |
| 75 | ((signed char) a == (unsigned char) B) + |
| 76 | (a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}} |
| 77 | (a < (unsigned int) B) + |
| 78 | (a < (unsigned short) B) + |
| 79 | (a < (unsigned char) B) + |
| 80 | ((long) a < B) + |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 81 | ((int) a < B) + |
| 82 | ((short) a < B) + |
| 83 | ((signed char) a < B) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 84 | ((long) a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}} |
| 85 | ((int) a < (unsigned int) B) + // expected-warning {{comparison of integers of different signs}} |
John McCall | 323ed74 | 2010-05-06 08:58:33 +0000 | [diff] [blame] | 86 | ((short) a < (unsigned short) B) + |
| 87 | ((signed char) a < (unsigned char) B) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 88 | |
| 89 | // (C,b) |
| 90 | (C == (unsigned long) b) + |
| 91 | (C == (unsigned int) b) + |
| 92 | (C == (unsigned short) b) + |
| 93 | (C == (unsigned char) b) + |
| 94 | ((long) C == b) + |
| 95 | ((int) C == b) + |
| 96 | ((short) C == b) + |
| 97 | ((signed char) C == b) + |
| 98 | ((long) C == (unsigned long) b) + |
| 99 | ((int) C == (unsigned int) b) + |
| 100 | ((short) C == (unsigned short) b) + |
| 101 | ((signed char) C == (unsigned char) b) + |
| 102 | (C < (unsigned long) b) + |
| 103 | (C < (unsigned int) b) + |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 104 | (C < (unsigned short) b) + |
| 105 | (C < (unsigned char) b) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 106 | ((long) C < b) + |
| 107 | ((int) C < b) + |
| 108 | ((short) C < b) + |
| 109 | ((signed char) C < b) + |
| 110 | ((long) C < (unsigned long) b) + |
| 111 | ((int) C < (unsigned int) b) + |
| 112 | ((short) C < (unsigned short) b) + |
| 113 | ((signed char) C < (unsigned char) b) + |
| 114 | |
| 115 | // (a,C) |
| 116 | (a == (unsigned long) C) + |
| 117 | (a == (unsigned int) C) + |
| 118 | (a == (unsigned short) C) + |
| 119 | (a == (unsigned char) C) + |
| 120 | ((long) a == C) + |
| 121 | ((int) a == C) + |
| 122 | ((short) a == C) + |
| 123 | ((signed char) a == C) + |
| 124 | ((long) a == (unsigned long) C) + |
| 125 | ((int) a == (unsigned int) C) + |
| 126 | ((short) a == (unsigned short) C) + |
| 127 | ((signed char) a == (unsigned char) C) + |
| 128 | (a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}} |
| 129 | (a < (unsigned int) C) + |
| 130 | (a < (unsigned short) C) + |
| 131 | (a < (unsigned char) C) + |
| 132 | ((long) a < C) + |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 133 | ((int) a < C) + |
| 134 | ((short) a < C) + |
| 135 | ((signed char) a < C) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 136 | ((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}} |
| 137 | ((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}} |
John McCall | 323ed74 | 2010-05-06 08:58:33 +0000 | [diff] [blame] | 138 | ((short) a < (unsigned short) C) + |
| 139 | ((signed char) a < (unsigned char) C) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 140 | |
| 141 | // (0x80000,b) |
| 142 | (0x80000 == (unsigned long) b) + |
| 143 | (0x80000 == (unsigned int) b) + |
| 144 | (0x80000 == (unsigned short) b) + |
| 145 | (0x80000 == (unsigned char) b) + |
| 146 | ((long) 0x80000 == b) + |
| 147 | ((int) 0x80000 == b) + |
| 148 | ((short) 0x80000 == b) + |
| 149 | ((signed char) 0x80000 == b) + |
| 150 | ((long) 0x80000 == (unsigned long) b) + |
| 151 | ((int) 0x80000 == (unsigned int) b) + |
| 152 | ((short) 0x80000 == (unsigned short) b) + |
| 153 | ((signed char) 0x80000 == (unsigned char) b) + |
| 154 | (0x80000 < (unsigned long) b) + |
| 155 | (0x80000 < (unsigned int) b) + |
| 156 | (0x80000 < (unsigned short) b) + |
| 157 | (0x80000 < (unsigned char) b) + |
| 158 | ((long) 0x80000 < b) + |
| 159 | ((int) 0x80000 < b) + |
| 160 | ((short) 0x80000 < b) + |
| 161 | ((signed char) 0x80000 < b) + |
| 162 | ((long) 0x80000 < (unsigned long) b) + |
| 163 | ((int) 0x80000 < (unsigned int) b) + |
| 164 | ((short) 0x80000 < (unsigned short) b) + |
| 165 | ((signed char) 0x80000 < (unsigned char) b) + |
| 166 | |
| 167 | // (a,0x80000) |
| 168 | (a == (unsigned long) 0x80000) + |
| 169 | (a == (unsigned int) 0x80000) + |
| 170 | (a == (unsigned short) 0x80000) + |
| 171 | (a == (unsigned char) 0x80000) + |
| 172 | ((long) a == 0x80000) + |
| 173 | ((int) a == 0x80000) + |
| 174 | ((short) a == 0x80000) + |
| 175 | ((signed char) a == 0x80000) + |
| 176 | ((long) a == (unsigned long) 0x80000) + |
| 177 | ((int) a == (unsigned int) 0x80000) + |
| 178 | ((short) a == (unsigned short) 0x80000) + |
| 179 | ((signed char) a == (unsigned char) 0x80000) + |
| 180 | (a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}} |
| 181 | (a < (unsigned int) 0x80000) + |
| 182 | (a < (unsigned short) 0x80000) + |
| 183 | (a < (unsigned char) 0x80000) + |
| 184 | ((long) a < 0x80000) + |
| 185 | ((int) a < 0x80000) + |
| 186 | ((short) a < 0x80000) + |
| 187 | ((signed char) a < 0x80000) + |
| 188 | ((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}} |
| 189 | ((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}} |
John McCall | 323ed74 | 2010-05-06 08:58:33 +0000 | [diff] [blame] | 190 | ((short) a < (unsigned short) 0x80000) + |
| 191 | ((signed char) a < (unsigned char) 0x80000) + |
John McCall | 5dbad3d | 2009-11-06 08:49:08 +0000 | [diff] [blame] | 192 | |
| 193 | 10 |
| 194 | ; |
John McCall | b13c87f | 2009-11-05 09:23:39 +0000 | [diff] [blame] | 195 | } |
John McCall | 842aef8 | 2009-12-09 09:09:27 +0000 | [diff] [blame] | 196 | |
| 197 | int test1(int i) { |
| 198 | enum en { zero }; |
| 199 | return i > zero; |
| 200 | } |
Douglas Gregor | 6e5122c | 2010-06-15 21:38:40 +0000 | [diff] [blame] | 201 | |
| 202 | enum E { e }; |
| 203 | void test2(int i, void *vp) { |
| 204 | if (test1 == vp) { } // expected-warning{{equality comparison between function pointer and void pointer}} |
| 205 | if (test1 == e) { } // expected-error{{comparison between pointer and integer}} |
| 206 | if (vp < 0) { } |
| 207 | if (test1 < e) { } // expected-error{{comparison between pointer and integer}} |
| 208 | } |