Bug 101156 - [10 Regression] ICE: ‘verify_gimple’ failed, verify_gimple_in_seq(gimple*)
Summary: [10 Regression] ICE: ‘verify_gimple’ failed, verify_gimple_in_seq(gimple*)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 11.2
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code, wrong-code
Depends on:
Blocks:
 
Reported: 2021-06-21 19:37 UTC by Chengnian Sun
Modified: 2023-07-07 09:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.1.1, 12.0
Known to fail: 11.1.0, 7.5.0, 8.5.0
Last reconfirmed: 2021-06-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chengnian Sun 2021-06-21 19:37:14 UTC
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/scratch/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.oJWiD4wb77-gcc-builder/gcc/configure --enable-languages=c,c++,lto --enable-checking-yes --enable-multiarch --prefix=/scratch/software/gcc-trunk --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20210621 (experimental) [master revision :ac955e7ab:3e42ff715697c75c4fb4aed550a8a15edb3eeea6] (GCC)

$ cat mutant.c
struct S {
  int i;
} baz(struct S *p) {
  setjmp(p--);
}

$ gcc-trunk  mutant.c
mutant.c: In function ‘baz’:
mutant.c:4:3: warning: implicit declaration of function ‘setjmp’ [-Wimplicit-function-declaration]
    4 |   setjmp(p--);
      |   ^~~~~~
mutant.c:3:3: error: type mismatch in ‘pointer_plus_expr’
    3 | } baz(struct S *p) {
      |   ^~~
struct S *

<<< error >>>

sizetype

p = _1 + 18446744073709551612;
mutant.c:3:3: internal compiler error: ‘verify_gimple’ failed
0xf4c4c5 verify_gimple_in_seq(gimple*)
	/tmp/tmp.oJWiD4wb77-gcc-builder/gcc/gcc/tree-cfg.c:5183
0xc3a336 gimplify_body(tree_node*, bool)
	/tmp/tmp.oJWiD4wb77-gcc-builder/gcc/gcc/gimplify.c:15422
0xc3a4d1 gimplify_function_tree(tree_node*)
	/tmp/tmp.oJWiD4wb77-gcc-builder/gcc/gcc/gimplify.c:15493
0xa8be17 cgraph_node::analyze()
	/tmp/tmp.oJWiD4wb77-gcc-builder/gcc/gcc/cgraphunit.c:670
0xa8ed11 analyze_functions
	/tmp/tmp.oJWiD4wb77-gcc-builder/gcc/gcc/cgraphunit.c:1234
0xa8f7e1 symbol_table::finalize_compilation_unit()
	/tmp/tmp.oJWiD4wb77-gcc-builder/gcc/gcc/cgraphunit.c:2508
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.
Comment 1 Martin Liška 2021-06-22 06:27:45 UTC
Started with r7-536-g381cdae49785fc4b.
Comment 2 Richard Biener 2021-06-22 06:54:10 UTC
I will have a look.
Comment 3 Richard Biener 2021-06-22 08:00:29 UTC
OK, so the issue is we're calling gimplify_expr (...., false /*allow_ssa*/)
on 'p--' and the gimplified sequence looks like the following on the pre_p
sequence:

 p.0_1 = p;
 p = p.0_1 + 18446744073709551612;

and the gimplify_expr result is just p.0_1.  Then we do

          /* Avoid the extra copy if possible.  */
          *expr_p = create_tmp_reg (TREE_TYPE (name));
          if (!gimple_nop_p (SSA_NAME_DEF_STMT (name)))
            gimple_set_lhs (SSA_NAME_DEF_STMT (name), *expr_p);
          release_ssa_name (name);

but obviously that disregards that there's other uses of p.0_1 already.
I suppose the above might be premature optimization but I'm going to gather
some statistics on that I guess.
Comment 4 GCC Commits 2021-06-22 13:31:13 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:b4e21c80462682c4e6e5e487fe87107b27f8b4bd

commit r12-1729-gb4e21c80462682c4e6e5e487fe87107b27f8b4bd
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jun 22 12:13:44 2021 +0200

    middle-end/101156 - remove not working optimization in gimplification
    
    This removes a premature and not working optimization from the
    gimplifier.  When gimplification is requested not to produce a SSA
    name we try to avoid generating a copy when we did so anyway but
    instead replace the LHS of its definition.  But that only works in
    case there are no uses of the SSA name already which is something
    we cannot easily check, so the following removes said optimization.
    
    Statistics on the whole bootstrap shows we hit this optimization
    only for libiberty/cp-demangle.c and overall we have 21652112
    gimplifications where just 240 copies are elided.  Preserving
    the optimization would require scanning the original expression
    and the pre and post sequences for SSA names and uses, that seems
    excessive to avoid these 240 copies.
    
    2021-06-22  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/101156
            * gimplify.c (gimplify_expr): Remove premature incorrect
            optimization.
    
            * gcc.dg/pr101156.c: New testcase.
Comment 5 Richard Biener 2021-06-22 13:32:08 UTC
Fixed on trunk sofar, unsure if worth backporting - we've not hit this in 5 years ;)
Comment 6 GCC Commits 2021-07-07 14:06:57 UTC
The releases/gcc-11 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:9e1173009150086a927a6f0e001fd04c5cac54cb

commit r11-8698-g9e1173009150086a927a6f0e001fd04c5cac54cb
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jun 22 12:13:44 2021 +0200

    middle-end/101156 - remove not working optimization in gimplification
    
    This removes a premature and not working optimization from the
    gimplifier.  When gimplification is requested not to produce a SSA
    name we try to avoid generating a copy when we did so anyway but
    instead replace the LHS of its definition.  But that only works in
    case there are no uses of the SSA name already which is something
    we cannot easily check, so the following removes said optimization.
    
    Statistics on the whole bootstrap shows we hit this optimization
    only for libiberty/cp-demangle.c and overall we have 21652112
    gimplifications where just 240 copies are elided.  Preserving
    the optimization would require scanning the original expression
    and the pre and post sequences for SSA names and uses, that seems
    excessive to avoid these 240 copies.
    
    2021-06-22  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/101156
            * gimplify.c (gimplify_expr): Remove premature incorrect
            optimization.
    
            * gcc.dg/pr101156.c: New testcase.
    
    (cherry picked from commit b4e21c80462682c4e6e5e487fe87107b27f8b4bd)
Comment 7 Richard Biener 2022-05-27 09:45:47 UTC
GCC 9 branch is being closed
Comment 8 Jakub Jelinek 2022-06-28 10:45:31 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 9 Richard Biener 2023-07-07 09:42:28 UTC
Fixed in GCC 11.2.