https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127010
Bug ID: 127010
Summary: [12/13/14/15 Regression] ICE during RTL expand of
switch over int; GCC 13+ runs out of memory
Product: gcc
Version: 12.5.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: lyican53 at sjtu dot edu.cn
Target Milestone: ---
Created attachment 65393
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65393&action=edit
preprocessed source that triggers the ICE
I found this in radare2's git history. They hit the problem with GCC 12.2.0 and
worked around it in commit bd3bedb7 (2025-02-16) by changing the return value
and local variable from int to char.
I can still reproduce it with GCC 12.5.0 using the attached preprocessed
source:
gcc -O2 -c testcase_buggy.i -o /dev/null
It fails during RTL expand at the switch in pickle_encode:
expand p/pickle/plugin.c: In function 'pickle_encode':
p/pickle/plugin.c:632:17: internal compiler error: Segmentation fault 632 |
switch (ob) { | ^~~~~~ 0x1a1edd6 internal_error(char const*, ...) ???:0 Please
submit a full bug report, with preprocessed source (by using -freport-bug).
I also tried the same testcase with the official GCC Docker images. GCC 11.5.0
compiles it, while 12.5.0 ICEs. With 13.4.0, 14.4.0, and 15.3.0, cc1 instead
keeps allocating memory until it is OOM-killed. radare2 reported the same
behavior with 14.2.0 as:
cc1: out of memory allocating 34359738352 bytes
The code has an inline function returning int, whose result is used as the
switch expression. The switch has about 68 cases. Changing the function return
type and the variable from int to char, as radare2 did, makes the problem go
away.
-fno-inline and -fno-jump-tables also make the testcase compile. On GCC 12.5.0,
-fno-tree-switch-conversion does not.
The attached testcase_buggy.i is unreduced (about 28k lines). I tried keeping
only the function containing the switch, but that no longer reproduces the ICE.