aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2017-02-21 18:57:23 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2017-02-21 18:57:23 +0100
commit3bb4311904171b4938f6682566a24180f318b196 (patch)
treeb4f077a5ec20715695c62f39daac6b4d371c27e2
parent664beaf2c19148677cc26c0fd6beaf2e56d2b6f3 (diff)
downloadgcc-3bb4311904171b4938f6682566a24180f318b196.zip
gcc-3bb4311904171b4938f6682566a24180f318b196.tar.gz
gcc-3bb4311904171b4938f6682566a24180f318b196.tar.bz2
re PR c++/79655 (ICE on invalid c++ code in cxx_eval_store_expression in cp/constexpr.c:3464)
PR c++/79655 * constexpr.c (cxx_eval_array_reference): Diagnose negative subscript. * g++.dg/cpp1y/constexpr-79655.C: New test. From-SVN: r245636
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/constexpr.c7
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/constexpr-79655.C18
4 files changed, 28 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 26ead8a..914f80c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
2017-02-21 Jakub Jelinek <jakub@redhat.com>
+ PR c++/79655
+ * constexpr.c (cxx_eval_array_reference): Diagnose negative subscript.
+
PR c++/79639
* constexpr.c (cxx_eval_store_expression): If *valp is a PTRMEM_CST,
call cplus_expand_constant on it first.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 14af617..3fe501a 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2263,9 +2263,10 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t,
nelts = cxx_eval_constant_expression (ctx, nelts, false, non_constant_p,
overflow_p);
VERIFY_CONSTANT (nelts);
- if (lval
- ? !tree_int_cst_le (index, nelts)
- : !tree_int_cst_lt (index, nelts))
+ if ((lval
+ ? !tree_int_cst_le (index, nelts)
+ : !tree_int_cst_lt (index, nelts))
+ || tree_int_cst_sgn (index) < 0)
{
diag_array_subscript (ctx, ary, index);
*non_constant_p = true;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 342f23f..9877624 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2017-02-21 Jakub Jelinek <jakub@redhat.com>
+ PR c++/79655
+ * g++.dg/cpp1y/constexpr-79655.C: New test.
+
PR c++/79639
* g++.dg/cpp1y/constexpr-79639.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-79655.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-79655.C
new file mode 100644
index 0000000..0be94b6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-79655.C
@@ -0,0 +1,18 @@
+// PR c++/79655
+// { dg-do compile { target c++14 } }
+
+constexpr int
+foo (int x, int y)
+{
+ int a[6] = { 1, 2, 3, 4, 5, 6 };
+ a[x] = 0;
+ return a[y];
+}
+
+constexpr int b = foo (0, -1); // { dg-error "is outside the bounds" }
+constexpr int c = foo (0, 6); // { dg-error "is outside the bounds" }
+constexpr int d = foo (6, 0); // { dg-error "is outside the bounds" }
+constexpr int e = foo (-1, 0); // { dg-error "is outside the bounds" }
+static_assert (foo (5, 5) == 0, "");
+static_assert (foo (4, 5) == 6, "");
+static_assert (foo (5, 4) == 5, "");