summaryrefslogtreecommitdiffstats
path: root/test/Sema/shift.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema/shift.c')
-rw-r--r--test/Sema/shift.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/Sema/shift.c b/test/Sema/shift.c
index 4273cab..df6b114 100644
--- a/test/Sema/shift.c
+++ b/test/Sema/shift.c
@@ -1,7 +1,9 @@
-// RUN: %clang -Wall -ffreestanding -fsyntax-only -Xclang -verify %s
+// 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,
@@ -32,6 +34,22 @@ void test() {
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
OpenPOWER on IntegriCloud