On 1/2/21 3:22 PM, Martin Sebor via Gcc-patches wrote:
> Attached is another revision of a patch I posted last July to keep
> the pretty-printer from crashing on MEM_REFs with void* arguments:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549746.html
>
> Besides avoiding the ICE and enhancing the MEM_REF detail and
> improving its format, this revision implements the suggestions
> in that discussion. To avoid code duplication it moves
> the handling to the C pretty-printer and changes the C++ front
> end to delegate to it. In addition, it includes a cast to
> the accessed type if it's different from/incompatible with
> (according to GIMPLE) that of the dereferenced pointer, or if
> the object is typeless. Lastly, it replaces the <unknown> in
> the output with either VLA names or the RHS of the GIMPLE
> expression (this improves the output when for dynamically
> allocated objects).
>
> As an aside, In my experience, MEM_REFs in warnings are limited
> to -Wuninitialized. I think other middle end warnings tend to
> avoid them. Those that involve invalid/out-of-bounds accesses
> replace them with either the target DECL (e.g., local variable,
> or FIELD_DECL), the allocation call (e.g., malloc), or the DECL
> of the pointer (e.g., PARM_DECL), followed by a note mentioning
> the offset into the object. I'd like to change -Wuninitialized
> at some point to follow the same style. So I see the value of
> the MEM_REF formatting enhancement mainly as a transient solution
> until that happens.
>
> Martin
>
> gcc-95768.diff
>
> PR c++/95768 - pretty-printer ICE on -Wuninitialized with allocated storage
>
> gcc/c-family/ChangeLog:
>
> PR c++/95768
> * c-pretty-print.c (c_pretty_printer::primary_expression): For
> SSA_NAMEs print VLA names and GIMPLE defining statements.
> (print_mem_ref): New function.
> (c_pretty_printer::unary_expression): Call it.
>
> gcc/cp/ChangeLog:
>
> PR c++/95768
> * error.c (dump_expr): Call c_pretty_printer::unary_expression.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/95768
> * g++.dg/pr95768.C: New test.
> * g++.dg/warn/Wuninitialized-12.C: New test.
> * gcc.dg/uninit-38.c: New test.
OK
jeff