Bug 97554 - ICE: during RTL pass: cprop /segfault in sbitmap
Summary: ICE: during RTL pass: cprop /segfault in sbitmap
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords:
: 82576 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-10-23 16:34 UTC by Rimvydas (RJ)
Modified: 2020-12-01 11:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-10-26 00:00:00


Attachments
reduced testcase (9.41 KB, application/x-xz)
2020-10-23 16:34 UTC, Rimvydas (RJ)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rimvydas (RJ) 2020-10-23 16:34:21 UTC
Created attachment 49435 [details]
reduced testcase

Attached is very reduced case from autogenerated verifier of observations, that is now failing to compile after including newest meteorological data.
gcc version 11.0.0 20201023 (experimental) linux x86_64

$ gcc -Wall -Wextra -O2 -c nwp_test.c
during RTL pass: cprop
nwp_test.c: In function 'obs_verif_body_entry':
nwp_test.c:14043:13: internal compiler error: Segmentation fault
14043 |   return RC;}
      |             ^
0xdef4ef crash_signal
        /z/gg/gcc/toplev.c:330
0x7fffed80b81f ???
        /z/glibc-2.32/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x1909e50 sbitmap_vector_alloc(unsigned int, unsigned int)
        /z/gg/gcc/sbitmap.c:171
0x1719767 alloc_cprop_mem
        /z/gg/gcc/cprop.c:557
0x1719767 one_cprop_pass
        /z/gg/gcc/cprop.c:1817
0x1719767 execute_rtl_cprop
        /z/gg/gcc/cprop.c:1931
0x1719767 execute
        /z/gg/gcc/cprop.c:1969
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.

Works with: 4.8.5 5.3 6.2 7.3 8.2
Fails with: 9.3  10.2 11-master

$ gcc-9 -O2 -c nwp_test.c
gcc-9: fatal error: Killed signal terminated program cc1

Able to compile with (time and memory usage is an issue):
gcc-9 -O2 -fno-ree
gcc-10 -O2 -fno-gcse -fno-ree
gcc-11 -O2 -fno-gcse
Comment 1 Richard Biener 2020-10-26 08:05:33 UTC
Confirmed.  We're doing

#1  0x0000000002343be5 in alloc_cprop_mem (n_blocks=249747, n_sets=137435)
    at /home/rguenther/src/gcc2/gcc/cprop.c:557
557       cprop_avloc = sbitmap_vector_alloc (n_blocks, n_sets);

where sbitmap_vector_alloc continues to use 'int' for things like size:

139     sbitmap *
140     sbitmap_vector_alloc (unsigned int n_vecs, unsigned int n_elms)
141     {
142       unsigned int i, bytes, offset, elm_bytes, size, amt, vector_bytes;
143       sbitmap *bitmap_vector;
144

and eventually 'amt' overflows:

  amt = vector_bytes + (n_vecs * elm_bytes);

(gdb) p vector_bytes
$8 = 1997976
(gdb) p n_vecs
$9 = 249747
(gdb) p elm_bytes
$10 = 17192
(gdb) p amt
$11 = 681104

I'll fix that part.
Comment 2 Richard Biener 2020-10-26 10:34:47 UTC
commit 50f9e1f4d458e36d306b2449c689e45492847f68 (HEAD -> trunk, origin/master, origin/HEAD)
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Oct 26 10:10:46 2020 +0100

    middle-end/97554 - avoid overflow in alloc size compute
    
    This avoids overflow in the allocation size computations in
    sbitmap_vector_alloc when the result exceeds 2GB.
    
    2020-10-26  Richard Biener  <rguenther@suse.de>
    
            * sbitmap.c (sbitmap_vector_alloc): Use size_t for byte
            quantities to avoid overflow.
Comment 3 Rimvydas (RJ) 2020-10-26 17:13:53 UTC
The g:50f9e1f4d458e36d306b2449c689e45492847f68 applied on top of gcc-10.2 release tarball also allows to compile without segfault in reasonable amount of time. Could this fix be added to gcc-10 branch for gcc 10.3 release?
Comment 4 Richard Biener 2020-12-01 10:12:45 UTC
*** Bug 82576 has been marked as a duplicate of this bug. ***
Comment 5 Richard Biener 2020-12-01 10:13:06 UTC
Sure, will backport.
Comment 6 GCC Commits 2020-12-01 10:32:24 UTC
The releases/gcc-10 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

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

commit r10-9098-g9d769cdde26d87043da0e1ffdee51010a71f49c2
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Oct 26 10:10:46 2020 +0100

    middle-end/97554 - avoid overflow in alloc size compute
    
    This avoids overflow in the allocation size computations in
    sbitmap_vector_alloc when the result exceeds 2GB.
    
    2020-10-26  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/97554
            * sbitmap.c (sbitmap_vector_alloc): Use size_t for byte
            quantities to avoid overflow.
    
    (cherry picked from commit 50f9e1f4d458e36d306b2449c689e45492847f68)
Comment 7 GCC Commits 2020-12-01 10:50:21 UTC
The releases/gcc-9 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:5005e6c2a8a8cacfd501fed16dc4ce3ee24e8b26

commit r9-9083-g5005e6c2a8a8cacfd501fed16dc4ce3ee24e8b26
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Oct 26 10:10:46 2020 +0100

    middle-end/97554 - avoid overflow in alloc size compute
    
    This avoids overflow in the allocation size computations in
    sbitmap_vector_alloc when the result exceeds 2GB.
    
    2020-10-26  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/97554
            * sbitmap.c (sbitmap_vector_alloc): Use size_t for byte
            quantities to avoid overflow.
    
    (cherry picked from commit 50f9e1f4d458e36d306b2449c689e45492847f68)
Comment 8 GCC Commits 2020-12-01 11:02:40 UTC
The releases/gcc-8 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:46384dc73076d945c9222b3f0850a9aa3e694eda

commit r8-10657-g46384dc73076d945c9222b3f0850a9aa3e694eda
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Oct 26 10:10:46 2020 +0100

    middle-end/97554 - avoid overflow in alloc size compute
    
    This avoids overflow in the allocation size computations in
    sbitmap_vector_alloc when the result exceeds 2GB.
    
    2020-10-26  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/97554
            * sbitmap.c (sbitmap_vector_alloc): Use size_t for byte
            quantities to avoid overflow.
    
    (cherry picked from commit 50f9e1f4d458e36d306b2449c689e45492847f68)
Comment 9 Richard Biener 2020-12-01 11:03:43 UTC
Fixed everywhere.