aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2017-10-19 16:03:07 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2017-10-19 10:03:07 -0600
commitf5ba8fd1087285a379cf25d549574330abdef6f0 (patch)
tree7c13139d786762d97da1313ca8b4fd19a3385e7e
parent9e878cf1bae7eba3a097dbb6b04d0bbca5bdb0e4 (diff)
downloadgcc-f5ba8fd1087285a379cf25d549574330abdef6f0.zip
gcc-f5ba8fd1087285a379cf25d549574330abdef6f0.tar.gz
gcc-f5ba8fd1087285a379cf25d549574330abdef6f0.tar.bz2
PR tree-optimization/82596 - missing -Warray-bounds on an out-of-bounds
PR tree-optimization/82596 - missing -Warray-bounds on an out-of-bounds index into string literal gcc/ChangeLog: * tree.c (array_at_struct_end_p): Handle STRING_CST. gcc/testsuite/ChangeLog: * gcc/testsuite/gcc.dg/pr82596.c: New test. From-SVN: r253902
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr82596.c27
-rw-r--r--gcc/tree.c3
4 files changed, 40 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c63d734..43c928b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2017-10-19 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/82596
+ * tree.c (array_at_struct_end_p): Handle STRING_CST.
+
2017-10-19 Eric Botcazou <ebotcazou@adacore.com>
* asan.c (handle_builtin_alloca): Deal with all alloca variants.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 138899a..31cf70b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-10-19 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/82596
+ * gcc/testsuite/gcc.dg/pr82596.c: New test.
+
2017-10-19 Eric Botcazou <ebotcazou@adacore.com>
* gcc.dg/Walloca-15.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr82596.c b/gcc/testsuite/gcc.dg/pr82596.c
new file mode 100644
index 0000000..5dc67c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82596.c
@@ -0,0 +1,27 @@
+/* PR tree-optimization/82596 - missing -Warray-bounds on an out-of-bounds
+ index into string literal
+ { dg-do compile }
+ { dg-options "-O2 -Warray-bounds" } */
+
+#define SIZE_MAX __SIZE_MAX__
+#define SSIZE_MAX __PTRDIFF_MAX__
+#define SSIZE_MIN (-SSIZE_MAX - 1)
+
+void sink (int, ...);
+
+#define T(arg) sink (arg)
+
+void test_cststring (int i)
+{
+ T (""[SSIZE_MIN]); /* { dg-warning "below array bounds" "string" { xfail lp64 } } */
+ T (""[SSIZE_MIN + 1]); /* { dg-warning "below array bounds" "string" } */
+ T (""[-1]); /* { dg-warning "below array bounds" "string" } */
+ T (""[0]);
+ T (""[1]); /* { dg-warning "above array bounds" "string" } */
+ T ("0"[2]); /* { dg-warning "above array bounds" "string" } */
+ T ("012"[2]);
+ T ("012"[3]);
+ T ("012"[4]); /* { dg-warning "above array bounds" "string" } */
+ T ("0123"[SSIZE_MAX]); /* { dg-warning "above array bounds" "string" } */
+ T ("0123"[SIZE_MAX]); /* { dg-warning "above array bounds" "string" } */
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 1b20ad6..62a4386 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -12549,6 +12549,9 @@ array_at_struct_end_p (tree ref)
else
return false;
+ if (TREE_CODE (ref) == STRING_CST)
+ return false;
+
while (handled_component_p (ref))
{
/* If the reference chain contains a component reference to a