1*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s 2*67e74705SXin Li // rdar://12202422 3*67e74705SXin Li 4*67e74705SXin Li int value(void); 5*67e74705SXin Li main()6*67e74705SXin Liint main() 7*67e74705SXin Li { 8*67e74705SXin Li int a = value(); 9*67e74705SXin Li if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} 10*67e74705SXin Li return 0; 11*67e74705SXin Li if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} 12*67e74705SXin Li return 0; 13*67e74705SXin Li if (a < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} 14*67e74705SXin Li return 0; 15*67e74705SXin Li if (a <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} 16*67e74705SXin Li return 0; 17*67e74705SXin Li if (a > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} 18*67e74705SXin Li return 0; 19*67e74705SXin Li if (a >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} 20*67e74705SXin Li return 0; 21*67e74705SXin Li 22*67e74705SXin Li if (0x1234567812345678L == a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} 23*67e74705SXin Li return 0; 24*67e74705SXin Li if (0x1234567812345678L != a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} 25*67e74705SXin Li return 0; 26*67e74705SXin Li if (0x1234567812345678L < a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} 27*67e74705SXin Li return 0; 28*67e74705SXin Li if (0x1234567812345678L <= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} 29*67e74705SXin Li return 0; 30*67e74705SXin Li if (0x1234567812345678L > a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} 31*67e74705SXin Li return 0; 32*67e74705SXin Li if (0x1234567812345678L >= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} 33*67e74705SXin Li return 0; 34*67e74705SXin Li if (a == 0x1234567812345678LL) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} 35*67e74705SXin Li return 0; 36*67e74705SXin Li if (a == -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} 37*67e74705SXin Li return 0; 38*67e74705SXin Li if (a < -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} 39*67e74705SXin Li return 0; 40*67e74705SXin Li if (a > -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}} 41*67e74705SXin Li return 0; 42*67e74705SXin Li if (a <= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} 43*67e74705SXin Li return 0; 44*67e74705SXin Li if (a >= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}} 45*67e74705SXin Li return 0; 46*67e74705SXin Li 47*67e74705SXin Li 48*67e74705SXin Li if (a == 0x12345678L) // no warning 49*67e74705SXin Li return 1; 50*67e74705SXin Li 51*67e74705SXin Li short s = value(); 52*67e74705SXin Li if (s == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} 53*67e74705SXin Li return 0; 54*67e74705SXin Li if (s != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} 55*67e74705SXin Li return 0; 56*67e74705SXin Li if (s < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} 57*67e74705SXin Li return 0; 58*67e74705SXin Li if (s <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} 59*67e74705SXin Li return 0; 60*67e74705SXin Li if (s > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} 61*67e74705SXin Li return 0; 62*67e74705SXin Li if (s >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} 63*67e74705SXin Li return 0; 64*67e74705SXin Li 65*67e74705SXin Li if (0x1234567812345678L == s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} 66*67e74705SXin Li return 0; 67*67e74705SXin Li if (0x1234567812345678L != s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} 68*67e74705SXin Li return 0; 69*67e74705SXin Li if (0x1234567812345678L < s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} 70*67e74705SXin Li return 0; 71*67e74705SXin Li if (0x1234567812345678L <= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} 72*67e74705SXin Li return 0; 73*67e74705SXin Li if (0x1234567812345678L > s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} 74*67e74705SXin Li return 0; 75*67e74705SXin Li if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} 76*67e74705SXin Li return 0; 77*67e74705SXin Li long l = value(); 78*67e74705SXin Li if (l == 0x1234567812345678L) 79*67e74705SXin Li return 0; 80*67e74705SXin Li if (l != 0x1234567812345678L) 81*67e74705SXin Li return 0; 82*67e74705SXin Li if (l < 0x1234567812345678L) 83*67e74705SXin Li return 0; 84*67e74705SXin Li if (l <= 0x1234567812345678L) 85*67e74705SXin Li return 0; 86*67e74705SXin Li if (l > 0x1234567812345678L) 87*67e74705SXin Li return 0; 88*67e74705SXin Li if (l >= 0x1234567812345678L) 89*67e74705SXin Li return 0; 90*67e74705SXin Li 91*67e74705SXin Li if (0x1234567812345678L == l) 92*67e74705SXin Li return 0; 93*67e74705SXin Li if (0x1234567812345678L != l) 94*67e74705SXin Li return 0; 95*67e74705SXin Li if (0x1234567812345678L < l) 96*67e74705SXin Li return 0; 97*67e74705SXin Li if (0x1234567812345678L <= l) 98*67e74705SXin Li return 0; 99*67e74705SXin Li if (0x1234567812345678L > l) 100*67e74705SXin Li return 0; 101*67e74705SXin Li if (0x1234567812345678L >= l) 102*67e74705SXin Li return 0; 103*67e74705SXin Li 104*67e74705SXin Li unsigned un = 0; 105*67e74705SXin Li if (un == 0x0000000000000000L) 106*67e74705SXin Li return 0; 107*67e74705SXin Li if (un != 0x0000000000000000L) 108*67e74705SXin Li return 0; 109*67e74705SXin Li if (un < 0x0000000000000000L) 110*67e74705SXin Li return 0; 111*67e74705SXin Li if (un <= 0x0000000000000000L) 112*67e74705SXin Li return 0; 113*67e74705SXin Li if (un > 0x0000000000000000L) 114*67e74705SXin Li return 0; 115*67e74705SXin Li if (un >= 0x0000000000000000L) 116*67e74705SXin Li return 0; 117*67e74705SXin Li 118*67e74705SXin Li if (0x0000000000000000L == un) 119*67e74705SXin Li return 0; 120*67e74705SXin Li if (0x0000000000000000L != un) 121*67e74705SXin Li return 0; 122*67e74705SXin Li if (0x0000000000000000L < un) 123*67e74705SXin Li return 0; 124*67e74705SXin Li if (0x0000000000000000L <= un) 125*67e74705SXin Li return 0; 126*67e74705SXin Li if (0x0000000000000000L > un) 127*67e74705SXin Li return 0; 128*67e74705SXin Li if (0x0000000000000000L >= un) 129*67e74705SXin Li return 0; 130*67e74705SXin Li float fl = 0; 131*67e74705SXin Li if (fl == 0x0000000000000000L) // no warning 132*67e74705SXin Li return 0; 133*67e74705SXin Li 134*67e74705SXin Li float dl = 0; 135*67e74705SXin Li if (dl == 0x0000000000000000L) // no warning 136*67e74705SXin Li return 0; 137*67e74705SXin Li 138*67e74705SXin Li enum E { 139*67e74705SXin Li yes, 140*67e74705SXin Li no, 141*67e74705SXin Li maybe 142*67e74705SXin Li }; 143*67e74705SXin Li enum E e; 144*67e74705SXin Li 145*67e74705SXin Li if (e == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'enum E' is always false}} 146*67e74705SXin Li return 0; 147*67e74705SXin Li 148*67e74705SXin Li return 1; 149*67e74705SXin Li } 150