From b5ebb71777112f2575c4abfc94439c7c9f13210e Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 19 Jun 2018 22:35:45 +0000 Subject: [PATCH] PR middle-end/85602 - -Warray-bounds fails to detect the out of bound array access gcc/testsuite/ChangeLog: * c-c++-common/attr-nonstring-8.c: Adjust text of expected warning to also match C++. From-SVN: r261774 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/Warray-bounds-28.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/Warray-bounds-28.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 04da05d23e1..5ce5b61c927 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-19 Martin Sebor + + PR tree-optimization/48560 + * gcc.dg/Warray-bounds-28.c: New test. + 2018-06-19 Martin Sebor PR middle-end/85602 diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-28.c b/gcc/testsuite/gcc.dg/Warray-bounds-28.c new file mode 100644 index 00000000000..c63c70ad389 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-28.c @@ -0,0 +1,15 @@ +/* PR tree-optimization/48560 - -Warray-bounds fails to detect the out of + bound array access + { dg-do compile } + { dg-options "-O2 -Warray-bounds" } */ + +char foo1 (int i) +{ + static char s[] = "foo"; + switch (i) + { + case 30: + return s[30]; /* { dg-warning "array subscript 30 is above array bounds" } */ + } + return s[i]; +} -- 2.30.2