diff options
author | Jason Merrill <jason@redhat.com> | 2016-08-01 15:01:03 +0000 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2016-08-01 15:01:03 +0000 |
commit | 90c9122116eda7ee906626a0469e53d5c7e10ae4 (patch) | |
tree | 10049b6204e11dba9e275b41e80f6900bdb77bf9 | |
parent | c406f7b6cae173e0e91bbfb70d470bd7aed801a0 (diff) |
PR c++/72766 - ICE with VLA
* constexpr.c (cxx_eval_pointer_plus_expression): Check constancy
of nelts.
* cp-gimplify.c (cp_fully_fold): Only maybe_constant_value in
C++11 and up.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@238957 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 4 | ||||
-rw-r--r-- | gcc/cp/cp-gimplify.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/vla16.C | 8 |
4 files changed, 22 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1037208d5bd..d792baf2475 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2016-08-01 Jason Merrill <jason@redhat.com> + + PR c++/72766 + * constexpr.c (cxx_eval_pointer_plus_expression): Check constancy + of nelts. + * cp-gimplify.c (cp_fully_fold): Only maybe_constant_value in + C++11 and up. + 2016-07-30 Martin Sebor <msebor@redhat.com> PR c++/60760 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 8bda97373b1..edade489401 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3581,6 +3581,10 @@ cxx_eval_pointer_plus_expression (const constexpr_ctx *ctx, tree t, tree type = TREE_TYPE (op00); t = fold_convert_loc (loc, ssizetype, TREE_OPERAND (op00, 1)); tree nelts = array_type_nelts_top (TREE_TYPE (TREE_OPERAND (op00, 0))); + nelts = cxx_eval_constant_expression (ctx, nelts, false, non_constant_p, + overflow_p); + if (*non_constant_p) + return NULL_TREE; /* Don't fold an out-of-bound access. */ if (!tree_int_cst_le (t, nelts)) return NULL_TREE; diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 59953a6ee04..e28c9dfc799 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1967,7 +1967,8 @@ cp_fully_fold (tree x) return x; /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't have to call both. */ - x = maybe_constant_value (x); + if (cxx_dialect >= cxx11) + x = maybe_constant_value (x); return cp_fold (x); } diff --git a/gcc/testsuite/g++.dg/ext/vla16.C b/gcc/testsuite/g++.dg/ext/vla16.C new file mode 100644 index 00000000000..c3e6ea1caba --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vla16.C @@ -0,0 +1,8 @@ +// PR c++/72766 +// { dg-options "-Wno-vla" } + +long fn1() { + const int a = fn1(); + int b[a]; + int c = *(&b[0] + sizeof(0)); +} |