https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102359

--- Comment #2 from qinzhao at gcc dot gnu.org ---
(In reply to Richard Biener from comment #1)
> Confirmed.  So we end with '&__closure->__this' which indeed isn't an lvalue.
> 
> The issue here is that we are initializing the VAR_DECL 'this' but that
> has a DECL_VALUE_EXPR expanding to &__closure->__this:
> 
> const struct A * const this [value-expr: &__closure->__this];
> 
> note the variable is const as well, so emitting a runtime initializer might
> have other issues (like trapping ...), or in this case, not being an lvalue.
> 
> But note the FE fails to mark the decl as TREE_READONLY - that would be an
> easy thing to check (and something we fail to check in
> is_var_need_auto_init).

Indeed, VAR_DECL "this" is:

(gdb) call debug_tree(t)
 <var_decl 0x7ffff7ff7cf0 this
    type <pointer_type 0x7fffe947a000
        type <record_type 0x7fffe9461930 A readonly needs-constructing
cxx-odr-p type_5 DF
            size <integer_cst 0x7fffe92f8f30 constant 64>
            unit-size <integer_cst 0x7fffe92f8f48 constant 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffe9461930 fields <function_decl 0x7fffe947f000 __dt > context
<translation_unit_decl 0x7fffe9306168 t.cpp>
            full-name "const struct A"
            needs-constructor X() X(constX&) this=(X&) n_parents=0
use_template=0 interface-unknown
            pointer_to_this <pointer_type 0x7fffe9461540> reference_to_this
<reference_type 0x7fffe947a2a0>>
        readonly sizes-gimplified unsigned DI size <integer_cst 0x7fffe92f8f30
64> unit-size <integer_cst 0x7fffe92f8f48 8>
        align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffe947a000>
    used unsigned read DI t.cpp:4:18 size <integer_cst 0x7fffe92f8f30 64>
unit-size <integer_cst 0x7fffe92f8f48 8>
    align:64 warn_if_not_align:0 context <function_decl 0x7fffe9465500
operator()>
    value-expr <addr_expr 0x7fffe9459b00 type <pointer_type 0x7fffe947a000>
        readonly
        arg:0 <component_ref 0x7fffe9472d50 type <record_type 0x7fffe9461930 A>
            readonly
            arg:0 <indirect_ref 0x7fffe9459ae0 type <record_type 0x7fffe94615e8
._anon_0>
                arg:0 <parm_decl 0x7fffe9475180 __closure>> arg:1 <field_decl
0x7fffe9327ab0 __this>
            t.cpp:4:18 start: t.cpp:4:18 finish: t.cpp:4:18>>>

It's not marked as "READONLY" by FE. 
this looks like a FE bug to me. 
I just feel strange why not marking "this" as "READONLY" hasn't caused any
other issue yet?


> Thus sth like
> 
> diff --git a/gcc/gimplify.c b/gcc/gimplify.c
> index f680292fd91..b2bfab47a2f 100644
> --- a/gcc/gimplify.c
> +++ b/gcc/gimplify.c
> @@ -1824,7 +1824,9 @@ gimple_add_padding_init_for_auto_var (tree decl, bool
> is_vla,
>  static bool
>  is_var_need_auto_init (tree decl)
>  {
> -  if (auto_var_p (decl)
> +  if (VAR_P (decl)
> +      && !TREE_READONLY (decl)
> +      && auto_var_p (decl)
>        && (flag_auto_var_init > AUTO_INIT_UNINITIALIZED)
>        && (!lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl)))
>        && !is_empty_type (TREE_TYPE (decl)))
> 
> should be needed.

If the FE can mark "this" as READONLY, the above will be the reasonable fix in
middle end. 
should we put this middle end fix in first and then transfer this bug to FE to
fix?
> 
> Jason, any idea?

Reply via email to