public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102359] New: ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a
@ 2021-09-16  8:54 marxin at gcc dot gnu.org
  2021-09-16  8:54 ` [Bug tree-optimization/102359] " marxin at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-09-16  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102359
           Summary: ICE gimplification failed since
                    r12-3433-ga25e0b5e6ac8a77a
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: qing.zhao at oracle dot com
  Target Milestone: ---

The following fails:

$ cat cxx.cpp
struct A {
  double a = 111;
  auto foo() {
    return [*this] { return a; };
  }
};
int X = A{}.foo()();

$ g++ cxx.cpp -c -ftrivial-auto-var-init=zero
gimplification failed:
&__closure->__this <addr_expr 0x7ffff77396c0
    type <pointer_type 0x7ffff7731000
        type <record_type 0x7ffff7718930 A readonly needs-constructing
cxx-odr-p type_5 DF
            size <integer_cst 0x7ffff75aff30 constant 64>
            unit-size <integer_cst 0x7ffff75aff48 constant 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff7718930 fields <function_decl 0x7ffff7736000 __dt > context
<translation_unit_decl 0x7ffff75bd168 cxx.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 0x7ffff7718540> reference_to_this
<reference_type 0x7ffff77312a0>>
        readonly sizes-gimplified unsigned DI size <integer_cst 0x7ffff75aff30
64> unit-size <integer_cst 0x7ffff75aff48 8>
        align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff7731000>
    readonly
    arg:0 <component_ref 0x7ffff7734690 type <record_type 0x7ffff7718930 A>
        readonly
        arg:0 <mem_ref 0x7ffff7737910 type <record_type 0x7ffff77185e8
._anon_0>
            arg:0 <parm_decl 0x7ffff772c180 __closure>
            arg:1 <integer_cst 0x7ffff7725e88 constant 0>
            cxx.cpp:4:18 start: cxx.cpp:4:18 finish: cxx.cpp:4:18>
        arg:1 <field_decl 0x7ffff75deab0 __this type <record_type
0x7ffff7718b28 A>
            used nonlocal decl_7 DF cxx.cpp:4:14 size <integer_cst
0x7ffff75aff30 64> unit-size <integer_cst 0x7ffff75aff48 8>
            align:64 warn_if_not_align:0 offset_align 128
            offset <integer_cst 0x7ffff75aff60 constant 0>
            bit-offset <integer_cst 0x7ffff75affa8 constant 0> context
<record_type 0x7ffff77182a0 ._anon_0> chain <function_decl 0x7ffff771c500
operator()>>
        cxx.cpp:4:18 start: cxx.cpp:4:18 finish: cxx.cpp:4:18>>
cxx.cpp: In lambda function:
cxx.cpp:4:18: internal compiler error: gimplification failed
    4 |     return [*this] { return a; };
      |                  ^
0xf2510a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/marxin/Programming/gcc/gcc/gimplify.c:15569
0xf31e2b gimplify_modify_expr
        /home/marxin/Programming/gcc/gcc/gimplify.c:5960
0xf2161f gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/marxin/Programming/gcc/gcc/gimplify.c:14556
0xf2515c gimplify_stmt(tree_node**, gimple**)
        /home/marxin/Programming/gcc/gcc/gimplify.c:7006
0xf25196 gimplify_and_add(tree_node*, gimple**)
        /home/marxin/Programming/gcc/gcc/gimplify.c:494
0xf25706 gimplify_assign(tree_node*, tree_node*, gimple**)
        /home/marxin/Programming/gcc/gcc/gimplify.c:16148
0xf33fc8 gimple_add_init_for_auto_var
        /home/marxin/Programming/gcc/gcc/gimplify.c:1777
0xf33fc8 gimplify_decl_expr
        /home/marxin/Programming/gcc/gcc/gimplify.c:1937
0xf21a03 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/marxin/Programming/gcc/gcc/gimplify.c:14753
0xf2515c gimplify_stmt(tree_node**, gimple**)
        /home/marxin/Programming/gcc/gcc/gimplify.c:7006
0xf22f33 gimplify_statement_list
        /home/marxin/Programming/gcc/gcc/gimplify.c:1997
0xf22f33 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/marxin/Programming/gcc/gcc/gimplify.c:15001
0xf2515c gimplify_stmt(tree_node**, gimple**)
        /home/marxin/Programming/gcc/gcc/gimplify.c:7006
0xf25fd0 gimplify_bind_expr
        /home/marxin/Programming/gcc/gcc/gimplify.c:1426
0xf21f1a gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/marxin/Programming/gcc/gcc/gimplify.c:14757
0xf2515c gimplify_stmt(tree_node**, gimple**)
        /home/marxin/Programming/gcc/gcc/gimplify.c:7006
0xf275e3 gimplify_body(tree_node*, bool)
        /home/marxin/Programming/gcc/gcc/gimplify.c:15802
0xf27a7c gimplify_function_tree(tree_node*)
        /home/marxin/Programming/gcc/gcc/gimplify.c:15956
0xd5c037 cgraph_node::analyze()
        /home/marxin/Programming/gcc/gcc/cgraphunit.c:670
0xd5ec77 analyze_functions
        /home/marxin/Programming/gcc/gcc/cgraphunit.c:1234
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/102359] ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a
  2021-09-16  8:54 [Bug tree-optimization/102359] New: ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a marxin at gcc dot gnu.org
@ 2021-09-16  8:54 ` marxin at gcc dot gnu.org
  2021-09-16  9:37 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-09-16  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1
   Last reconfirmed|                            |2021-09-16
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Target Milestone|---                         |12.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/102359] ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a
  2021-09-16  8:54 [Bug tree-optimization/102359] New: ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a 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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-16  9:37 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
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).
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.

Jason, any idea?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/102359] ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a
  2021-09-16  8:54 [Bug tree-optimization/102359] New: ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a 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
  2021-10-05 23:14 ` cvs-commit at gcc dot gnu.org
  2021-10-05 23:16 ` qinzhao at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2021-09-29 16:28 UTC (permalink / raw)
  To: gcc-bugs

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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/102359] ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a
  2021-09-16  8:54 [Bug tree-optimization/102359] New: ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a marxin at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-09-29 16:28 ` qinzhao at gcc dot gnu.org
@ 2021-10-05 23:14 ` cvs-commit at gcc dot gnu.org
  2021-10-05 23:16 ` qinzhao at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-05 23:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Qing Zhao <qinzhao@gcc.gnu.org>:

https://gcc.gnu.org/g:433516e1c6b1f8eeceeceb83cec5ea02a14065dc

commit r12-4200-g433516e1c6b1f8eeceeceb83cec5ea02a14065dc
Author: qing zhao <qing.zhao@oracle.com>
Date:   Tue Oct 5 16:14:00 2021 -0700

    Not add initialization for variables been initialized by FEs [PR102359]

    C++ FE creates proxy variables, which have associated DECL_VALUE_EXPR
    and have been initialized by FE. For such auto variable, we should not
    add initialization when -ftrivial-auto-var-init presents.

            PR middle-end/102359

    gcc/ChangeLog:

    2021-10-05  qing zhao  <qing.zhao@oracle.com>

            * gimplify.c (gimplify_decl_expr): Not add initialization for an
            auto variable when it has been initialized by frontend.

    gcc/testsuite/ChangeLog:

    2021-10-05  qing zhao  <qing.zhao@oracle.com>

            * g++.dg/pr102359_1.C: New test.
            * g++.dg/pr102359_2.C: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/102359] ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a
  2021-09-16  8:54 [Bug tree-optimization/102359] New: ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a marxin at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-10-05 23:14 ` cvs-commit at gcc dot gnu.org
@ 2021-10-05 23:16 ` qinzhao at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2021-10-05 23:16 UTC (permalink / raw)
  To: gcc-bugs

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

qinzhao at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from qinzhao at gcc dot gnu.org ---
fixed

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-05 23:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16  8:54 [Bug tree-optimization/102359] New: ICE gimplification failed since r12-3433-ga25e0b5e6ac8a77a 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
2021-10-05 23:14 ` cvs-commit at gcc dot gnu.org
2021-10-05 23:16 ` qinzhao at gcc dot gnu.org

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