Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 1 | // RUN: %clang -Wall -fsyntax-only -Xclang -verify %s |
Ryan Flynn | d043968 | 2009-08-07 16:20:20 +0000 | [diff] [blame] | 2 | |
| 3 | #include <limits.h> |
| 4 | |
| 5 | enum { |
| 6 | X = 1 << 0, |
| 7 | Y = 1 << 1, |
| 8 | Z = 1 << 2 |
| 9 | }; |
Chris Lattner | 1dcf2c8 | 2007-12-13 07:28:16 +0000 | [diff] [blame] | 10 | |
| 11 | void test() { |
| 12 | char c; |
Ryan Flynn | d043968 | 2009-08-07 16:20:20 +0000 | [diff] [blame] | 13 | |
| 14 | c = 0 << 0; |
Ryan Flynn | 8045c73 | 2009-08-08 19:18:23 +0000 | [diff] [blame] | 15 | c = 0 << 1; |
Ryan Flynn | d043968 | 2009-08-07 16:20:20 +0000 | [diff] [blame] | 16 | c = 1 << 0; |
| 17 | c = 1 << -0; |
| 18 | c = 1 >> -0; |
| 19 | c = 1 << -1; // expected-warning {{shift count is negative}} |
| 20 | c = 1 >> -1; // expected-warning {{shift count is negative}} |
| 21 | c = 1 << c; |
Ryan Flynn | 8045c73 | 2009-08-08 19:18:23 +0000 | [diff] [blame] | 22 | c <<= 0; |
| 23 | c >>= 0; |
Ryan Flynn | d043968 | 2009-08-07 16:20:20 +0000 | [diff] [blame] | 24 | c <<= 1; |
| 25 | c >>= 1; |
| 26 | c <<= -1; // expected-warning {{shift count is negative}} |
| 27 | c >>= -1; // expected-warning {{shift count is negative}} |
| 28 | c <<= 999999; // expected-warning {{shift count >= width of type}} |
| 29 | c >>= 999999; // expected-warning {{shift count >= width of type}} |
| 30 | c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}} |
| 31 | c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}} |
| 32 | c <<= CHAR_BIT+1; // expected-warning {{shift count >= width of type}} |
| 33 | c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}} |
| 34 | (void)((long)c << CHAR_BIT); |
Chris Lattner | 1dcf2c8 | 2007-12-13 07:28:16 +0000 | [diff] [blame] | 35 | } |
Ryan Flynn | 8045c73 | 2009-08-08 19:18:23 +0000 | [diff] [blame] | 36 | |
| 37 | #define a 0 |
| 38 | #define ashift 8 |
| 39 | enum { b = (a << ashift) }; |
| 40 | |