public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "qinzhao at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/102359] ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a
Date: Wed, 29 Sep 2021 16:28:56 +0000	[thread overview]
Message-ID: <bug-102359-4-glQjUdo3dM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102359-4@http.gcc.gnu.org/bugzilla/>

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?

  parent reply	other threads:[~2021-09-29 16:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16  8:54 [Bug tree-optimization/102359] New: " marxin at gcc dot gnu.org
2021-09-16  8:54 ` [Bug tree-optimization/102359] " marxin at gcc dot gnu.org
2021-09-16  9:37 ` rguenth at gcc dot gnu.org
2021-09-29 16:28 ` qinzhao at gcc dot gnu.org [this message]
2021-10-05 23:14 ` cvs-commit at gcc dot gnu.org
2021-10-05 23:16 ` qinzhao at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-102359-4-glQjUdo3dM@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).