On Mon, Feb 14, 2022 at 4:31 PM Richard Biener
<richard.guent...@gmail.com> wrote:
>
> On Mon, Feb 14, 2022 at 1:54 PM Roger Sayle <ro...@nextmovesoftware.com> 
> wrote:
> >
> >
> >
> > 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.
>
> Hmm, IMHO "fixing" something to error_mark after it has possibly be used
> looks broken.
>
> I don't like trying to paper over this in useless_type_conversion_p, the
> predicate should not be called on an error_mark_node type.
>
> Alternatively we might want to create an error_type_node that is at least
> a type (with main variant error_type_node and TREE_CODE ERROR_TYPE, etc.).
> But likely more complicated than avoiding to mess with the type of 'x' after
> the fact?

That is,

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index c701f07befe..29658ade6d7 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -2964,14 +2964,12 @@ duplicate_decls (tree newdecl, tree olddecl)
     {
       /* Avoid `unused variable' and other warnings for OLDDECL.  */
       suppress_warning (olddecl, OPT_Wunused);
-      /* If the types are completely different, poison them both with
+      /* If the types are completely different, poison the new with
         error_mark_node.  */
       if (TREE_CODE (TREE_TYPE (newdecl)) != TREE_CODE (TREE_TYPE (olddecl))
          && olddecl != error_mark_node
          && seen_error ())
        {
-         if (TREE_CODE (olddecl) != FUNCTION_DECL)
-           TREE_TYPE (olddecl) = error_mark_node;
          if (TREE_CODE (newdecl) != FUNCTION_DECL)
            TREE_TYPE (newdecl) = error_mark_node;
        }

can you check what happens with that?

>
> Richard.
>
> >
> > 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
> >
> > --
> >
> >
> >

Reply via email to