This simple fix to the middle-end, resolves PR c/104506, by adding an
explicit check for error_mark_node to useless_type_conversion_p. I first trying fixing this in the C front-end, but the type is valid at the point that the NOP_EXPR is created, so the poisoned type leaks to the middle-end. Returning either true or false from useless_type_conversion_p avoids the ICE-after-error. Apologies to Andrew Pinski, I hadn't noticed that he'd assigned this PR to himself until after my regression testing had finished. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check with no new failures. Ok for mainline? 2022-02-14 Roger Sayle <ro...@nextmovesoftware.com> gcc/ChangeLog PR c/104506 * gimple-expr.cc (useless_type_conversion_p): Add a check for error_mark_node. gcc/testsuite/ChangeLog PR c/104506 * gcc.dg/pr104506.c: New test case. Roger --
diff --git a/gcc/gimple-expr.cc b/gcc/gimple-expr.cc index f9a650b..e63fa3c 100644 --- a/gcc/gimple-expr.cc +++ b/gcc/gimple-expr.cc @@ -83,6 +83,9 @@ useless_type_conversion_p (tree outer_type, tree inner_type) return false; } + if (inner_type == error_mark_node) + return true; + /* From now on qualifiers on value types do not matter. */ inner_type = TYPE_MAIN_VARIANT (inner_type); outer_type = TYPE_MAIN_VARIANT (outer_type); diff --git a/gcc/testsuite/gcc.dg/pr104506.c b/gcc/testsuite/gcc.dg/pr104506.c new file mode 100644 index 0000000..79cec1a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104506.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +double x; +/* { dg-message "note: previous declaration" "previous declaration" { target *-* + * -* } .-1 } */ + +void foo (void) +{ + x; +} + +int x; /* { dg-error "conflicting types" } */ +