On Tue, 9 Jun 2020, Jakub Jelinek wrote:

> Hi!
> 
> The C FE in the MEM_REF printing ICEs if the type of the first argument
> (which due to useless pointer conversions can be an arbitrary type) is a
> pointer to an incomplete type.  The code just wants to avoid printing a cast
> if it is a pointer to single byte elements.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2020-06-08  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR c/95580
>       * c-pretty-print.c (c_pretty_printer::unary_expression): Handle the
>       case when MEM_REF's first argument has type pointer to incomplete type.
> 
>       * gcc.dg/pr95580.c: New test.
> 
> --- gcc/c-family/c-pretty-print.c.jj  2020-06-08 10:21:38.651225945 +0200
> +++ gcc/c-family/c-pretty-print.c     2020-06-08 19:11:27.623658024 +0200
> @@ -1789,8 +1789,9 @@ c_pretty_printer::unary_expression (tree
>         if (!integer_zerop (TREE_OPERAND (e, 1)))
>           {
>             pp_c_left_paren (this);
> -           if (!integer_onep (TYPE_SIZE_UNIT
> -                              (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
> +           tree type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0)));
> +           if (TYPE_SIZE_UNIT (type) == NULL_TREE
> +               || !integer_onep (TYPE_SIZE_UNIT (type)))
>               pp_c_type_cast (this, ptr_type_node);
>           }
>         pp_c_cast_expression (this, TREE_OPERAND (e, 0));
> --- gcc/testsuite/gcc.dg/pr95580.c.jj 2020-06-08 19:27:51.191128586 +0200
> +++ gcc/testsuite/gcc.dg/pr95580.c    2020-06-08 19:27:26.487493595 +0200
> @@ -0,0 +1,16 @@
> +/* PR c/95580 */
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -W -fno-tree-dce" } */
> +
> +void bar (void);
> +
> +void
> +foo (int x)
> +{
> +  if (x == 0)
> +    {
> +      void *p = __builtin_malloc (4);
> +      ((char *)p)[1] ^= 1;   /* { dg-warning "may be used uninitialized" } */
> +    }
> +  bar ();
> +}
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Reply via email to