This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to fix ICE-on-invalid with ?: (PR c++/84138)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Wed, 31 Jan 2018 12:28:33 +0100
- Subject: C++ PATCH to fix ICE-on-invalid with ?: (PR c++/84138)
- Authentication-results: sourceware.org; auth=none
This fixes an ICE-on-invalid, where we're passing error_mark_node to
useless_type_conversion_p which can't handle that.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2018-01-31 Marek Polacek <polacek@redhat.com>
PR c++/84138
* cp-gimplify.c (cp_fold): Check if X is an error node before
calling useless_type_conversion_p.
* g++.dg/diagnostic/pr84138.C: New test.
diff --git gcc/cp/cp-gimplify.c gcc/cp/cp-gimplify.c
index 21859251795..55a9d278dbe 100644
--- gcc/cp/cp-gimplify.c
+++ gcc/cp/cp-gimplify.c
@@ -2356,6 +2356,7 @@ cp_fold (tree x)
/* A COND_EXPR might have incompatible types in branches if one or both
arms are bitfields. If folding exposed such a branch, fix it up. */
if (TREE_CODE (x) != code
+ && x != error_mark_node
&& !useless_type_conversion_p (TREE_TYPE (org_x), TREE_TYPE (x)))
x = fold_convert (TREE_TYPE (org_x), x);
diff --git gcc/testsuite/g++.dg/diagnostic/pr84138.C gcc/testsuite/g++.dg/diagnostic/pr84138.C
index e69de29bb2d..5c48b9b164a 100644
--- gcc/testsuite/g++.dg/diagnostic/pr84138.C
+++ gcc/testsuite/g++.dg/diagnostic/pr84138.C
@@ -0,0 +1,8 @@
+// PR c++/84138
+
+char
+foo()
+{
+ const int i = 0 = 0; // { dg-error "lvalue required as left operand" }
+ return 1 ? 0 : (char)i;
+} // { dg-warning "control reaches" }
Marek