aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/c-c++-common')
-rw-r--r--gcc/testsuite/c-c++-common/Wshift-negative-value-1.c49
-rw-r--r--gcc/testsuite/c-c++-common/Wshift-negative-value-2.c49
-rw-r--r--gcc/testsuite/c-c++-common/Wshift-negative-value-3.c49
-rw-r--r--gcc/testsuite/c-c++-common/Wshift-negative-value-4.c49
-rw-r--r--gcc/testsuite/c-c++-common/Wshift-negative-value-5.c50
-rw-r--r--gcc/testsuite/c-c++-common/Wshift-negative-value-6.c50
6 files changed, 296 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/Wshift-negative-value-1.c b/gcc/testsuite/c-c++-common/Wshift-negative-value-1.c
new file mode 100644
index 0000000..5d803ad
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wshift-negative-value-1.c
@@ -0,0 +1,49 @@
+/* PR c/65179 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wextra" } */
+/* { dg-additional-options "-std=c++11" { target c++ } } */
+
+enum E {
+ A = 0 << 1,
+ B = 1 << 1,
+ C = -1 << 1, /* { dg-warning "left shift of negative value|not an integer constant" } */
+ D = 0 >> 1,
+ E = 1 >> 1,
+ F = -1 >> 1
+};
+
+int
+left (int x)
+{
+ /* Warn for LSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z << x;
+ r += o << x;
+ r += m << x; /* { dg-warning "left shift of negative value" } */
+ r += 0 << x;
+ r += 1 << x;
+ r += -1 << x; /* { dg-warning "left shift of negative value" } */
+ r += -1U << x;
+ return r;
+}
+
+int
+right (int x)
+{
+ /* Shouldn't warn for RSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z >> x;
+ r += o >> x;
+ r += m >> x;
+ r += 0 >> x;
+ r += 1 >> x;
+ r += -1 >> x;
+ r += -1U >> x;
+ return r;
+}
diff --git a/gcc/testsuite/c-c++-common/Wshift-negative-value-2.c b/gcc/testsuite/c-c++-common/Wshift-negative-value-2.c
new file mode 100644
index 0000000..fc89af1
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wshift-negative-value-2.c
@@ -0,0 +1,49 @@
+/* PR c/65179 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wshift-negative-value" } */
+/* { dg-additional-options "-std=c++11" { target c++ } } */
+
+enum E {
+ A = 0 << 1,
+ B = 1 << 1,
+ C = -1 << 1, /* { dg-warning "left shift of negative value" } */
+ D = 0 >> 1,
+ E = 1 >> 1,
+ F = -1 >> 1
+};
+
+int
+left (int x)
+{
+ /* Warn for LSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z << x;
+ r += o << x;
+ r += m << x; /* { dg-warning "left shift of negative value" } */
+ r += 0 << x;
+ r += 1 << x;
+ r += -1 << x; /* { dg-warning "left shift of negative value" } */
+ r += -1U << x;
+ return r;
+}
+
+int
+right (int x)
+{
+ /* Shouldn't warn for RSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z >> x;
+ r += o >> x;
+ r += m >> x;
+ r += 0 >> x;
+ r += 1 >> x;
+ r += -1 >> x;
+ r += -1U >> x;
+ return r;
+}
diff --git a/gcc/testsuite/c-c++-common/Wshift-negative-value-3.c b/gcc/testsuite/c-c++-common/Wshift-negative-value-3.c
new file mode 100644
index 0000000..bf9b1a0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wshift-negative-value-3.c
@@ -0,0 +1,49 @@
+/* PR c/65179 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wextra -Wno-shift-negative-value" } */
+/* { dg-additional-options "-std=c++11" { target c++ } } */
+
+enum E {
+ A = 0 << 1,
+ B = 1 << 1,
+ C = -1 << 1,
+ D = 0 >> 1,
+ E = 1 >> 1,
+ F = -1 >> 1
+};
+
+int
+left (int x)
+{
+ /* Warn for LSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z << x;
+ r += o << x;
+ r += m << x; /* { dg-bogus "left shift of negative value" } */
+ r += 0 << x;
+ r += 1 << x;
+ r += -1 << x; /* { dg-bogus "left shift of negative value" } */
+ r += -1U << x;
+ return r;
+}
+
+int
+right (int x)
+{
+ /* Shouldn't warn for RSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z >> x;
+ r += o >> x;
+ r += m >> x;
+ r += 0 >> x;
+ r += 1 >> x;
+ r += -1 >> x;
+ r += -1U >> x;
+ return r;
+}
diff --git a/gcc/testsuite/c-c++-common/Wshift-negative-value-4.c b/gcc/testsuite/c-c++-common/Wshift-negative-value-4.c
new file mode 100644
index 0000000..85fbd0e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wshift-negative-value-4.c
@@ -0,0 +1,49 @@
+/* PR c/65179 */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+/* { dg-additional-options "-std=c++11" { target c++ } } */
+
+enum E {
+ A = 0 << 1,
+ B = 1 << 1,
+ C = -1 << 1,
+ D = 0 >> 1,
+ E = 1 >> 1,
+ F = -1 >> 1
+};
+
+int
+left (int x)
+{
+ /* Warn for LSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z << x;
+ r += o << x;
+ r += m << x; /* { dg-bogus "left shift of negative value" } */
+ r += 0 << x;
+ r += 1 << x;
+ r += -1 << x; /* { dg-bogus "left shift of negative value" } */
+ r += -1U << x;
+ return r;
+}
+
+int
+right (int x)
+{
+ /* Shouldn't warn for RSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z >> x;
+ r += o >> x;
+ r += m >> x;
+ r += 0 >> x;
+ r += 1 >> x;
+ r += -1 >> x;
+ r += -1U >> x;
+ return r;
+}
diff --git a/gcc/testsuite/c-c++-common/Wshift-negative-value-5.c b/gcc/testsuite/c-c++-common/Wshift-negative-value-5.c
new file mode 100644
index 0000000..74ecd1e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wshift-negative-value-5.c
@@ -0,0 +1,50 @@
+/* PR c/65179 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wshift-negative-value" } */
+/* { dg-additional-options "-std=c++03" { target c++ } } */
+/* { dg-additional-options "-std=c90" { target c } } */
+
+enum E {
+ A = 0 << 1,
+ B = 1 << 1,
+ C = -1 << 1, /* { dg-warning "left shift of negative value" } */
+ D = 0 >> 1,
+ E = 1 >> 1,
+ F = -1 >> 1
+};
+
+int
+left (int x)
+{
+ /* Warn for LSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z << x;
+ r += o << x;
+ r += m << x; /* { dg-warning "left shift of negative value" } */
+ r += 0 << x;
+ r += 1 << x;
+ r += -1 << x; /* { dg-warning "left shift of negative value" } */
+ r += -1U << x;
+ return r;
+}
+
+int
+right (int x)
+{
+ /* Shouldn't warn for RSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z >> x;
+ r += o >> x;
+ r += m >> x;
+ r += 0 >> x;
+ r += 1 >> x;
+ r += -1 >> x;
+ r += -1U >> x;
+ return r;
+}
diff --git a/gcc/testsuite/c-c++-common/Wshift-negative-value-6.c b/gcc/testsuite/c-c++-common/Wshift-negative-value-6.c
new file mode 100644
index 0000000..de9db52
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wshift-negative-value-6.c
@@ -0,0 +1,50 @@
+/* PR c/65179 */
+/* { dg-do compile } */
+/* { dg-options "-O -Wextra" } */
+/* { dg-additional-options "-std=c++03" { target c++ } } */
+/* { dg-additional-options "-std=c90" { target c } } */
+
+enum E {
+ A = 0 << 1,
+ B = 1 << 1,
+ C = -1 << 1, /* { dg-bogus "left shift of negative value" } */
+ D = 0 >> 1,
+ E = 1 >> 1,
+ F = -1 >> 1
+};
+
+int
+left (int x)
+{
+ /* Warn for LSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z << x;
+ r += o << x;
+ r += m << x; /* { dg-bogus "left shift of negative value" } */
+ r += 0 << x;
+ r += 1 << x;
+ r += -1 << x; /* { dg-bogus "left shift of negative value" } */
+ r += -1U << x;
+ return r;
+}
+
+int
+right (int x)
+{
+ /* Shouldn't warn for RSHIFT_EXPR. */
+ const int z = 0;
+ const int o = 1;
+ const int m = -1;
+ int r = 0;
+ r += z >> x;
+ r += o >> x;
+ r += m >> x;
+ r += 0 >> x;
+ r += 1 >> x;
+ r += -1 >> x;
+ r += -1U >> x;
+ return r;
+}