From 19c37faad10950f693872a4be018cfd9bc81804a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 3 Jan 2018 13:16:13 +0100 Subject: [PATCH] re PR c++/83634 (ICE in useless_type_conversion_p, at gimple-expr.c:86) PR c++/83634 * cp-gimplify.c (cp_fold) : If the operand folds to error_mark_node, return error_mark_node. * g++.dg/parse/pr83634.C: New test. From-SVN: r256174 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/cp-gimplify.c | 15 ++++++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/parse/pr83634.C | 11 +++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/parse/pr83634.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 750a9a8f94f..9dfb293e7f3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2018-01-03 Jakub Jelinek + PR c++/83634 + * cp-gimplify.c (cp_fold) : If the operand folds to + error_mark_node, return error_mark_node. + Update copyright years. 2018-01-02 Jakub Jelinek diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 4f607289539..c090ee7fcbd 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -2112,7 +2112,20 @@ cp_fold (tree x) case NON_LVALUE_EXPR: if (VOID_TYPE_P (TREE_TYPE (x))) - return x; + { + /* This is just to make sure we don't end up with casts to + void from error_mark_node. If we just return x, then + cp_fold_r might fold the operand into error_mark_node and + leave the conversion in the IR. STRIP_USELESS_TYPE_CONVERSION + during gimplification doesn't like such casts. + Don't create a new tree if op0 != TREE_OPERAND (x, 0), the + folding of the operand should be in the caches and if in cp_fold_r + it will modify it in place. */ + op0 = cp_fold (TREE_OPERAND (x, 0)); + if (op0 == error_mark_node) + x = error_mark_node; + break; + } loc = EXPR_LOCATION (x); op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 822c29d640d..cff788b6a92 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-03 Jakub Jelinek + + PR c++/83634 + * g++.dg/parse/pr83634.C: New test. + 2018-01-03 Thomas Koenig PR fortran/83664 diff --git a/gcc/testsuite/g++.dg/parse/pr83634.C b/gcc/testsuite/g++.dg/parse/pr83634.C new file mode 100644 index 00000000000..70a396eb421 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/pr83634.C @@ -0,0 +1,11 @@ +// PR c++/83634 +// { dg-do compile } + +void +foo () +{ + const int x = fn (); // { dg-error "was not declared in this scope" } + short n; + for (n = x; n < 100; ++n) + ; +} -- 2.30.2