aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-04-15 12:47:41 -0400
committerPatrick Palka <ppalka@redhat.com>2020-04-16 08:58:40 -0400
commiteffcb4181e143bc390286a489ff849768a49f6af (patch)
tree1f8b06662fc21d4c9b0103fa8520b773d2404f1f
parent44b326839d864fc10c459916abcc97f35a9ac3de (diff)
downloadgcc-effcb4181e143bc390286a489ff849768a49f6af.zip
gcc-effcb4181e143bc390286a489ff849768a49f6af.tar.gz
gcc-effcb4181e143bc390286a489ff849768a49f6af.tar.bz2
c++: Error recovery with erroneous DECL_INITIAL [PR94475]
Here we're ICE'ing in do_narrow during error-recovery, because ocp_convert returns error_mark_node after it attempts to reduce a const decl to its erroneous DECL_INITIAL via scalar_constant_value, and we later pass this error_mark_node to fold_build2 which isn't prepared to handle error_mark_nodes. We could fix this ICE in do_narrow by checking if ocp_convert returns error_mark_node, but for the sake of consistency and for better error recovery it seems it'd be preferable if ocp_convert didn't care that a const decl's initializer is erroneous and would instead proceed as if the decl was not const, which is the approach that this patch takes. gcc/cp/ChangeLog: PR c++/94475 * cvt.c (ocp_convert): If the result of scalar_constant_value is erroneous, ignore it and use the original expression. gcc/testsuite/ChangeLog: PR c++/94475 * g++.dg/conversion/err-recover2.C: New test. * g++.dg/diagnostic/pr84138.C: Remove now-bogus warning. * g++.dg/warn/Wsign-compare-8.C: Remove now-bogus warning.
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/cvt.c4
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/g++.dg/conversion/err-recover2.C10
-rw-r--r--gcc/testsuite/g++.dg/diagnostic/pr84138.C2
-rw-r--r--gcc/testsuite/g++.dg/warn/Wsign-compare-8.C2
6 files changed, 28 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3e32405..b2acd89 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-16 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/94475
+ * cvt.c (ocp_convert): If the result of scalar_constant_value is
+ erroneous, ignore it and use the original expression.
+
2020-04-16 Jakub Jelinek <jakub@redhat.com>
PR c++/94571
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index a3b8096..656e7fd 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -723,7 +723,9 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
if (!CLASS_TYPE_P (type))
{
e = mark_rvalue_use (e);
- e = scalar_constant_value (e);
+ tree v = scalar_constant_value (e);
+ if (!error_operand_p (v))
+ e = v;
}
if (error_operand_p (e))
return error_mark_node;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ed44204..756f1d7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-16 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/94475
+ * g++.dg/conversion/err-recover2.C: New test.
+ * g++.dg/diagnostic/pr84138.C: Remove now-bogus warning.
+ * g++.dg/warn/Wsign-compare-8.C: Remove now-bogus warning.
+
2020-04-16 Richard Sandiford <richard.sandiford@arm.com>
PR rtl-optimization/94605
diff --git a/gcc/testsuite/g++.dg/conversion/err-recover2.C b/gcc/testsuite/g++.dg/conversion/err-recover2.C
new file mode 100644
index 0000000..437e1a9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/err-recover2.C
@@ -0,0 +1,10 @@
+// PR c++/94475
+// { dg-do compile }
+
+unsigned char
+sr ()
+{
+ const unsigned char xz = EI; // { dg-error "not declared" }
+
+ return xz - (xz >> 1);
+}
diff --git a/gcc/testsuite/g++.dg/diagnostic/pr84138.C b/gcc/testsuite/g++.dg/diagnostic/pr84138.C
index 5c48b9b..0035230 100644
--- a/gcc/testsuite/g++.dg/diagnostic/pr84138.C
+++ b/gcc/testsuite/g++.dg/diagnostic/pr84138.C
@@ -5,4 +5,4 @@ foo()
{
const int i = 0 = 0; // { dg-error "lvalue required as left operand" }
return 1 ? 0 : (char)i;
-} // { dg-warning "control reaches" }
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
index 237ba84..4d26881 100644
--- a/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
+++ b/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C
@@ -5,4 +5,4 @@ bool foo (char c)
{
const int i = 0 = 0; // { dg-error "lvalue" }
return c = i;
-} // { dg-warning "control reaches" }
+}