blob: df6b1141bdfc7c82d81a28efb3daa426662c4dc7 [file] [log] [blame]
// RUN: %clang -Wall -Wshift-sign-overflow -ffreestanding -fsyntax-only -Xclang -verify %s
#include <limits.h>
#define WORD_BIT (sizeof(int) * CHAR_BIT)
enum {
X = 1 << 0,
Y = 1 << 1,
Z = 1 << 2
};
void test() {
char c;
c = 0 << 0;
c = 0 << 1;
c = 1 << 0;
c = 1 << -0;
c = 1 >> -0;
c = 1 << -1; // expected-warning {{shift count is negative}}
c = 1 >> -1; // expected-warning {{shift count is negative}}
c = 1 << c;
c <<= 0;
c >>= 0;
c <<= 1;
c >>= 1;
c <<= -1; // expected-warning {{shift count is negative}}
c >>= -1; // expected-warning {{shift count is negative}}
c <<= 999999; // expected-warning {{shift count >= width of type}}
c >>= 999999; // expected-warning {{shift count >= width of type}}
c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}
c <<= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
(void)((long)c << CHAR_BIT);
int i;
i = 1 << (WORD_BIT - 2);
i = 2 << (WORD_BIT - 1); // expected-warning {{bits to represent, but 'int' only has}}
i = 1 << (WORD_BIT - 1); // expected-warning {{overrides the sign bit of the shift expression}}
i = -1 << (WORD_BIT - 1);
i = 0 << (WORD_BIT - 1);
i = (char)1 << (WORD_BIT - 2);
unsigned u;
u = 1U << (WORD_BIT - 1);
u = 5U << (WORD_BIT - 1);
long long int lli;
lli = INT_MIN << 2; // expected-warning {{bits to represent, but 'int' only has}}
lli = 1LL << (sizeof(long long) * CHAR_BIT - 2);
}
#define a 0
#define ashift 8
enum { b = (a << ashift) };