146171917dc87caf0c7a741a7301f36db2e20b132Mike Stump// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s -Wno-unreachable-code
2d28f815705497f23c2747d61b7834f2d7ea78283Chris Lattner
3d28f815705497f23c2747d61b7834f2d7ea78283Chris Lattnerint test(char *C) { // nothing here should warn.
4d28f815705497f23c2747d61b7834f2d7ea78283Chris Lattner  return C != ((void*)0);
5d28f815705497f23c2747d61b7834f2d7ea78283Chris Lattner  return C != (void*)0;
6d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor  return C != 0;
706c0f5b1bb1623a93a2bc4c345fb3be52a2b22a7Chris Lattner  return C != 1;  // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
8d28f815705497f23c2747d61b7834f2d7ea78283Chris Lattner}
9d28f815705497f23c2747d61b7834f2d7ea78283Chris Lattner
1045aa4557fe4210034e85f4a807ff637a9dd146d6John McCallint ints(long a, unsigned long b) {
115dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall  enum EnumA {A};
125dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall  enum EnumB {B};
135dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall  enum EnumC {C = 0x10000};
145dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall  return
155dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         // (a,b)
165dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned long) b) +  // expected-warning {{comparison of integers of different signs}}
175dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned int) b) +
185dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned short) b) +
195dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned char) b) +
205dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == b) +  // expected-warning {{comparison of integers of different signs}}
215dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == b) +  // expected-warning {{comparison of integers of different signs}}
225dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) a == b) +  // expected-warning {{comparison of integers of different signs}}
235dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) a == b) +  // expected-warning {{comparison of integers of different signs}}
245dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == (unsigned long) b) +  // expected-warning {{comparison of integers of different signs}}
255dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == (unsigned int) b) +  // expected-warning {{comparison of integers of different signs}}
26323ed74658bc8375278eabf074b4777458376540John McCall         ((short) a == (unsigned short) b) +
27323ed74658bc8375278eabf074b4777458376540John McCall         ((signed char) a == (unsigned char) b) +
285dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned long) b) +  // expected-warning {{comparison of integers of different signs}}
295dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned int) b) +
305dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned short) b) +
315dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned char) b) +
325dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < b) +  // expected-warning {{comparison of integers of different signs}}
335dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < b) +  // expected-warning {{comparison of integers of different signs}}
345dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) a < b) +  // expected-warning {{comparison of integers of different signs}}
355dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) a < b) +  // expected-warning {{comparison of integers of different signs}}
365dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < (unsigned long) b) +  // expected-warning {{comparison of integers of different signs}}
375dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < (unsigned int) b) +  // expected-warning {{comparison of integers of different signs}}
38323ed74658bc8375278eabf074b4777458376540John McCall         ((short) a < (unsigned short) b) +
39323ed74658bc8375278eabf074b4777458376540John McCall         ((signed char) a < (unsigned char) b) +
405dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall
415dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         // (A,b)
425dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A == (unsigned long) b) +
435dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A == (unsigned int) b) +
445dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A == (unsigned short) b) +
455dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A == (unsigned char) b) +
465dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) A == b) +
475dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) A == b) +
485dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) A == b) +
495dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) A == b) +
505dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) A == (unsigned long) b) +
515dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) A == (unsigned int) b) +
525dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) A == (unsigned short) b) +
535dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) A == (unsigned char) b) +
545dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A < (unsigned long) b) +
555dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A < (unsigned int) b) +
565dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A < (unsigned short) b) +
575dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (A < (unsigned char) b) +
585dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) A < b) +
595dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) A < b) +
605dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) A < b) +
615dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) A < b) +
625dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) A < (unsigned long) b) +
635dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) A < (unsigned int) b) +
645dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) A < (unsigned short) b) +
655dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) A < (unsigned char) b) +
665dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall
675dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         // (a,B)
685dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned long) B) +
695dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned int) B) +
705dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned short) B) +
715dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned char) B) +
725dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == B) +
735dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == B) +
745dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) a == B) +
755dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) a == B) +
765dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == (unsigned long) B) +
775dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == (unsigned int) B) +
785dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) a == (unsigned short) B) +
795dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) a == (unsigned char) B) +
805dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned long) B) +  // expected-warning {{comparison of integers of different signs}}
815dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned int) B) +
825dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned short) B) +
835dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned char) B) +
845dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < B) +
855dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < B) +
865dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) a < B) +
875dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) a < B) +
885dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < (unsigned long) B) +  // expected-warning {{comparison of integers of different signs}}
895dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < (unsigned int) B) +  // expected-warning {{comparison of integers of different signs}}
90323ed74658bc8375278eabf074b4777458376540John McCall         ((short) a < (unsigned short) B) +
91323ed74658bc8375278eabf074b4777458376540John McCall         ((signed char) a < (unsigned char) B) +
925dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall
935dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         // (C,b)
945dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (C == (unsigned long) b) +
955dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (C == (unsigned int) b) +
967adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         (C == (unsigned short) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned short' is always false}}
977adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         (C == (unsigned char) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned char' is always false}}
985dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) C == b) +
995dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) C == b) +
1005dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) C == b) +
1015dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) C == b) +
1025dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) C == (unsigned long) b) +
1035dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) C == (unsigned int) b) +
1045dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) C == (unsigned short) b) +
1055dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) C == (unsigned char) b) +
1065dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (C < (unsigned long) b) +
1075dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (C < (unsigned int) b) +
1087adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         (C < (unsigned short) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned short' is always false}}
1097adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         (C < (unsigned char) b) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'unsigned char' is always false}}
1105dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) C < b) +
1115dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) C < b) +
1125dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) C < b) +
1135dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) C < b) +
1145dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) C < (unsigned long) b) +
1155dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) C < (unsigned int) b) +
1165dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) C < (unsigned short) b) +
1175dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) C < (unsigned char) b) +
1185dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall
1195dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         // (a,C)
1205dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned long) C) +
1215dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned int) C) +
1225dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned short) C) +
1235dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned char) C) +
1245dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == C) +
1255dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == C) +
1267adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         ((short) a == C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'short' is always false}}
1277adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         ((signed char) a == C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'signed char' is always false}}
1285dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == (unsigned long) C) +
1295dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == (unsigned int) C) +
1305dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) a == (unsigned short) C) +
1315dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) a == (unsigned char) C) +
1325dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned long) C) +  // expected-warning {{comparison of integers of different signs}}
1335dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned int) C) +
1345dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned short) C) +
1355dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned char) C) +
1365dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < C) +
1375dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < C) +
1387adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         ((short) a < C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'short' is always true}}
1397adf3a9f84688f334a1cd977317bb42f9e06c9f4Ted Kremenek         ((signed char) a < C) + // expected-warning {{comparison of constant 'C' (65536) with expression of type 'signed char' is always true}}
1405dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < (unsigned long) C) +  // expected-warning {{comparison of integers of different signs}}
1415dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < (unsigned int) C) +  // expected-warning {{comparison of integers of different signs}}
142323ed74658bc8375278eabf074b4777458376540John McCall         ((short) a < (unsigned short) C) +
143323ed74658bc8375278eabf074b4777458376540John McCall         ((signed char) a < (unsigned char) C) +
1445dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall
1455dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         // (0x80000,b)
1465dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (0x80000 == (unsigned long) b) +
1475dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (0x80000 == (unsigned int) b) +
148a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         (0x80000 == (unsigned short) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned short' is always false}}
149a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         (0x80000 == (unsigned char) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned char' is always false}}
1505dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) 0x80000 == b) +
1515dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) 0x80000 == b) +
1525dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) 0x80000 == b) +
1535dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) 0x80000 == b) +
1545dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) 0x80000 == (unsigned long) b) +
1555dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) 0x80000 == (unsigned int) b) +
1565dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) 0x80000 == (unsigned short) b) +
1575dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) 0x80000 == (unsigned char) b) +
1585dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (0x80000 < (unsigned long) b) +
1595dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (0x80000 < (unsigned int) b) +
160a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         (0x80000 < (unsigned short) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned short' is always false}}
161a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         (0x80000 < (unsigned char) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned char' is always false}}
1625dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) 0x80000 < b) +
1635dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) 0x80000 < b) +
1645dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) 0x80000 < b) +
1655dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) 0x80000 < b) +
1665dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) 0x80000 < (unsigned long) b) +
1675dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) 0x80000 < (unsigned int) b) +
1685dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) 0x80000 < (unsigned short) b) +
1695dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) 0x80000 < (unsigned char) b) +
1705dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall
1715dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         // (a,0x80000)
1725dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned long) 0x80000) +
1735dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned int) 0x80000) +
1745dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned short) 0x80000) +
1755dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a == (unsigned char) 0x80000) +
1765dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == 0x80000) +
1775dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == 0x80000) +
178a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         ((short) a == 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'short' is always false}}
179a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         ((signed char) a == 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'signed char' is always false}}
1805dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a == (unsigned long) 0x80000) +
1815dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a == (unsigned int) 0x80000) +
1825dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((short) a == (unsigned short) 0x80000) +
1835dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((signed char) a == (unsigned char) 0x80000) +
1845dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned long) 0x80000) +  // expected-warning {{comparison of integers of different signs}}
1855dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned int) 0x80000) +
1865dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned short) 0x80000) +
1875dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         (a < (unsigned char) 0x80000) +
1885dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < 0x80000) +
1895dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < 0x80000) +
190a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         ((short) a < 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'short' is always true}}
191a193f20916f0e0e5a3b0f76ca69e2b3870c1a325Fariborz Jahanian         ((signed char) a < 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'signed char' is always true}}
1925dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((long) a < (unsigned long) 0x80000) +  // expected-warning {{comparison of integers of different signs}}
1935dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         ((int) a < (unsigned int) 0x80000) +  // expected-warning {{comparison of integers of different signs}}
194323ed74658bc8375278eabf074b4777458376540John McCall         ((short) a < (unsigned short) 0x80000) +
195323ed74658bc8375278eabf074b4777458376540John McCall         ((signed char) a < (unsigned char) 0x80000) +
1965dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall
197bc021702e67a1c11d72a926f995cf418bb456315John McCall         // We should be able to avoid warning about this.
198bc021702e67a1c11d72a926f995cf418bb456315John McCall         (b != (a < 4 ? 1 : 2)) +
199bc021702e67a1c11d72a926f995cf418bb456315John McCall
2005dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall         10
2015dbad3d46c43e8051dac0c3775bcbaf8f1a6b8feJohn McCall    ;
20245aa4557fe4210034e85f4a807ff637a9dd146d6John McCall}
20345aa4557fe4210034e85f4a807ff637a9dd146d6John McCall
2046365e3e22bcec4b95c5b1ed47d501134b375a75aChris Lattnerint equal(char *a, const char *b) {
20577878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff    return a == b;
20677878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff}
2074e92acf3b747b994e50fbf7bfe8ef71cdda20c50Eli Friedman
2084e92acf3b747b994e50fbf7bfe8ef71cdda20c50Eli Friedmanint arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
2094e92acf3b747b994e50fbf7bfe8ef71cdda20c50Eli Friedman  int d = (a == c);
2104e92acf3b747b994e50fbf7bfe8ef71cdda20c50Eli Friedman  return a == b; // expected-warning {{comparison of distinct pointer types}}
2114e92acf3b747b994e50fbf7bfe8ef71cdda20c50Eli Friedman}
212149f1386c60aa07de0f6a5d43ab524b22af68059Chris Lattner
2136365e3e22bcec4b95c5b1ed47d501134b375a75aChris Lattnerint pointers(int *a) {
21406c0f5b1bb1623a93a2bc4c345fb3be52a2b22a7Chris Lattner  return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
21506c0f5b1bb1623a93a2bc4c345fb3be52a2b22a7Chris Lattner  return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
216149f1386c60aa07de0f6a5d43ab524b22af68059Chris Lattner  return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
217149f1386c60aa07de0f6a5d43ab524b22af68059Chris Lattner}
218149f1386c60aa07de0f6a5d43ab524b22af68059Chris Lattner
2193075e760ceb73b6fafc2fb4977ad68552d83aef8Eli Friedmanint function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) {
220149f1386c60aa07de0f6a5d43ab524b22af68059Chris Lattner  return a > b; // expected-warning {{ordered comparison of function pointers}}
221d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor  return function_pointers > function_pointers; // expected-warning {{self-comparison always evaluates to false}} expected-warning{{ordered comparison of function pointers}}
2223075e760ceb73b6fafc2fb4977ad68552d83aef8Eli Friedman  return a > c; // expected-warning {{comparison of distinct pointer types}}
223149f1386c60aa07de0f6a5d43ab524b22af68059Chris Lattner  return a == (void *) 0;
2243075e760ceb73b6fafc2fb4977ad68552d83aef8Eli Friedman  return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
225149f1386c60aa07de0f6a5d43ab524b22af68059Chris Lattner}
226f93343764765b24f53e389c7dd35f90901925451Douglas Gregor
2273075e760ceb73b6fafc2fb4977ad68552d83aef8Eli Friedmanint void_pointers(void* foo) {
2283075e760ceb73b6fafc2fb4977ad68552d83aef8Eli Friedman  return foo == (void*) 0;
2293075e760ceb73b6fafc2fb4977ad68552d83aef8Eli Friedman  return foo == (void*) 1;
230f93343764765b24f53e389c7dd35f90901925451Douglas Gregor}
231842aef8d942a880eeb9535d40de31a86838264cbJohn McCall
232d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor
233842aef8d942a880eeb9535d40de31a86838264cbJohn McCallint test1(int i) {
234842aef8d942a880eeb9535d40de31a86838264cbJohn McCall  enum en { zero };
235842aef8d942a880eeb9535d40de31a86838264cbJohn McCall  return i > zero;
236842aef8d942a880eeb9535d40de31a86838264cbJohn McCall}
237f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall
238f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall// PR5937
239f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCallint test2(int i32) {
240f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  struct foo {
241f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    unsigned int u8 : 8;
242f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    unsigned long long u31 : 31;
243f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    unsigned long long u32 : 32;
244f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    unsigned long long u63 : 63;
245f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    unsigned long long u64 : 64;
246f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  } *x;
247f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall
248f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  if (x->u8 == i32) { // comparison in int32, exact
249f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    return 0;
250f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  } else if (x->u31 == i32) { // comparison in int32, exact
251f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    return 1;
252f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  } else if (x->u32 == i32) { // expected-warning {{comparison of integers of different signs}}
253f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    return 2;
254f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  } else if (x->u63 == i32) { // comparison in uint64, exact because ==
255f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    return 3;
256f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  } else if (x->u64 == i32) { // expected-warning {{comparison of integers of different signs}}
257f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    return 4;
258f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  } else {
259f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    return 5;
260f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  }
261f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall}
262f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall
263f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall// PR5887
264f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCallvoid test3() {
265f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  unsigned short x, y;
266f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  unsigned int z;
267f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall  if ((x > y ? x : y) > z)
268f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall    (void) 0;
269f2370c9b4aade940e2253b5b33262ba507d1d71fJohn McCall}
2700acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCall
2710acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCall// PR5961
2720acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCallextern char *ptr4;
2730acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCallvoid test4() {
2740acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCall  long value;
2750acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCall  if (value < (unsigned long) &ptr4) // expected-warning {{comparison of integers of different signs}}
2760acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCall    return;
2770acc311bf73c85fd34ce6f89a4e786b7ecd214aaJohn McCall}
278d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCall
279d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCall// PR4807
280d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCallint test5(unsigned int x) {
281d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCall  return (x < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
282d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCall    && (0 > x)   // expected-warning {{comparison of 0 > unsigned expression is always false}}
283d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCall    && (x >= 0)  // expected-warning {{comparison of unsigned expression >= 0 is always true}}
284d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCall    && (0 <= x); // expected-warning {{comparison of 0 <= unsigned expression is always true}}
285d1b47bf17fde73fac67d8664bd65273742c00ecdJohn McCall}
2863aae6093dd8f3aecb66d7ff1f4b44e6a86765db4John McCall
2873aae6093dd8f3aecb66d7ff1f4b44e6a86765db4John McCallint test6(unsigned i, unsigned power) {
2883aae6093dd8f3aecb66d7ff1f4b44e6a86765db4John McCall  unsigned x = (i < (1 << power) ? i : 0);
2893aae6093dd8f3aecb66d7ff1f4b44e6a86765db4John McCall  return x != 3 ? 1 << power : i;
2903aae6093dd8f3aecb66d7ff1f4b44e6a86765db4John McCall}
291e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek
292e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek// <rdar://problem/8414119> enum >= (enum)0 comparison should not generate any warnings
293e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenekenum rdar8414119_Vals { X, Y, Z };
294e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek#define ZERO 0
295e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek#define CHECK(x) (x >= X)
296e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenekvoid rdar8414119_foo(enum rdar8414119_Vals v) {
297e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek  if (CHECK(v)) // no-warning
298e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek   return;
299e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek  if (v >= X) // no-warning
300e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek   return;
301e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek}
302e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenekint rdar8414119_bar(unsigned x) {
303e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek  return x >= ZERO; // no-warning
304e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek}
305e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek#undef ZERO
306e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek#undef CHECK
307e3b159c0d4a93db8586861ff011b5a10de4ae6efTed Kremenek
308372e103dab4239ec52b65b9eda69fd43c0b348d4John McCallint rdar8511238() {
309372e103dab4239ec52b65b9eda69fd43c0b348d4John McCall  enum A { A_foo, A_bar };
310372e103dab4239ec52b65b9eda69fd43c0b348d4John McCall  enum A a;
311372e103dab4239ec52b65b9eda69fd43c0b348d4John McCall  if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
312372e103dab4239ec52b65b9eda69fd43c0b348d4John McCall    return 0;
313372e103dab4239ec52b65b9eda69fd43c0b348d4John McCall  return 20;
314372e103dab4239ec52b65b9eda69fd43c0b348d4John McCall}
315862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall
316862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall// PR10336
317862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCallint test9(int sv, unsigned uv, long slv) {
318862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall  return sv == (uv ^= slv); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}}
319862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall}
320862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall
321862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCallvoid test10(void) {
322862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall  int si;
323862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall  unsigned int ui;
324862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall  long sl;
325862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall
326862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall  _Bool b;
327862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall  b = (si == (ui = sl)); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}}
328862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall  b = (si == (ui = sl&15));
329862ff87c0d306af8dfdbe7ac59f181a5815546e5John McCall}
330b17ee5bff0d7986c14cdddb279e0131bd7f9678dEli Friedman
331b17ee5bff0d7986c14cdddb279e0131bd7f9678dEli Friedman// PR11572
332b17ee5bff0d7986c14cdddb279e0131bd7f9678dEli Friedmanstruct test11S { unsigned x : 30; };
333b17ee5bff0d7986c14cdddb279e0131bd7f9678dEli Friedmanint test11(unsigned y, struct test11S *p) {
334b17ee5bff0d7986c14cdddb279e0131bd7f9678dEli Friedman  return y > (p->x >> 24); // no-warning
335b17ee5bff0d7986c14cdddb279e0131bd7f9678dEli Friedman}
3366d3b93d631640125f912339df19b0d2a15af5c9bDouglas Gregor
3376d3b93d631640125f912339df19b0d2a15af5c9bDouglas Gregortypedef char one_char[1];
3386d3b93d631640125f912339df19b0d2a15af5c9bDouglas Gregortypedef char two_chars[2];
3396d3b93d631640125f912339df19b0d2a15af5c9bDouglas Gregor
3406d3b93d631640125f912339df19b0d2a15af5c9bDouglas Gregorvoid test12(unsigned a) {
3416d3b93d631640125f912339df19b0d2a15af5c9bDouglas Gregor  if (0 && -1 > a) { }
3426d3b93d631640125f912339df19b0d2a15af5c9bDouglas Gregor}
343