|
1 |
| -// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare %s -Wno-unreachable-code |
2 |
| -// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtype-limits %s -Wno-unreachable-code |
| 1 | +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare %s -Wno-unreachable-code -DTEST=1 |
| 2 | +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtype-limits %s -Wno-unreachable-code -DTEST=2 |
3 | 3 |
|
4 | 4 | int test(char *C) { // nothing here should warn.
|
5 | 5 | return C != ((void*)0);
|
@@ -419,3 +419,65 @@ void pr36008(enum PR36008EnumTest lhs) {
|
419 | 419 | if (x == y) x = y; // no warning
|
420 | 420 | if (y == x) y = x; // no warning
|
421 | 421 | }
|
| 422 | + |
| 423 | +int test13(unsigned a, int b) { |
| 424 | + return a > ~(95 != b); // expected-warning {{comparison of integers of different signs}} |
| 425 | +} |
| 426 | + |
| 427 | +int test14(unsigned a, unsigned b) { |
| 428 | + return a > ~b; // no-warning |
| 429 | +} |
| 430 | + |
| 431 | +int test15(unsigned a, int b) { |
| 432 | + return a > -(95 != b); // expected-warning {{comparison of integers of different signs}} |
| 433 | +} |
| 434 | + |
| 435 | +int test16(unsigned a, unsigned b) { |
| 436 | + return a > -b; // no-warning |
| 437 | +} |
| 438 | + |
| 439 | +int test17(int a, unsigned b) { |
| 440 | + return a > -(-b); // expected-warning {{comparison of integers of different signs}} |
| 441 | +} |
| 442 | + |
| 443 | +int test18(int a) { |
| 444 | + return a == -(-2147483648); // expected-warning {{result of comparison of constant 2147483648 with expression of type 'int' is always false}} |
| 445 | +} |
| 446 | + |
| 447 | +int test19(int n) { |
| 448 | + return -(n & 15) <= -15; // no-warning |
| 449 | +} |
| 450 | + |
| 451 | +#if TEST == 1 |
| 452 | +int test20(int n) { |
| 453 | + return -(n & 15) <= -17; // expected-warning {{result of comparison of 5-bit signed value <= -17 is always false}} |
| 454 | +} |
| 455 | +#endif |
| 456 | + |
| 457 | +int test21(short n) { |
| 458 | + return -n == 32768; // no-warning |
| 459 | +} |
| 460 | + |
| 461 | +#if TEST == 1 |
| 462 | +int test22(short n) { |
| 463 | + return -n == 65536; // expected-warning {{result of comparison of 17-bit signed value == 65536 is always false}} |
| 464 | +} |
| 465 | +#endif |
| 466 | + |
| 467 | +int test23(unsigned short n) { |
| 468 | + return ~n == 32768; // no-warning |
| 469 | +} |
| 470 | + |
| 471 | +int test24(short n) { |
| 472 | + return ~n == 32767; // no-warning |
| 473 | +} |
| 474 | + |
| 475 | +#if TEST == 1 |
| 476 | +int test25(unsigned short n) { |
| 477 | + return ~n == 65536; // expected-warning {{result of comparison of 17-bit signed value == 65536 is always false}} |
| 478 | +} |
| 479 | + |
| 480 | +int test26(short n) { |
| 481 | + return ~n == 32768; // expected-warning {{result of comparison of 16-bit signed value == 32768 is always false}} |
| 482 | +} |
| 483 | +#endif |
0 commit comments