#1130962 m68k: Miscompilation at -O2

Package:
gcc-15
Source:
gcc-15
Description:
GNU C compiler
Submitter:
Camm Maguire
Date:
2026-03-18 16:27:02 UTC
Severity:
normal
Tags:
#1130962#5
Date:
2026-03-16 13:06:06 UTC
From:
To:
Dear Maintainer,

At -O2 gcc miscompiles the following snippet of C code

	V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});

as the gdb transcript below demonstrates.  In particular, the starting
address of _y, which should be V2048, is offset by 4 bytes.  The
problem vanishes at -O1.

=============================================================================
(gdb) b 17163
Breakpoint 4 at 0x23b04f2: file pcl_gcl/gcl_pcl_dfun.c, line 17163.
(gdb) c
Continuing.

Breakpoint 4, LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun (V2046=0xe44078,
    V2047=0x1888b10) at pcl_gcl/gcl_pcl_dfun.c:17163
17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b04f2 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+514>:	moveal %a3@,%a0
(gdb) p/x fcall.valp
$35 = 0x0
(gdb) p V2048
$36 = -1073746348
(gdb) p/x V2048
$37 = 0xbfffee54
(gdb) p *(ul *)0xbfffee54@4
$38 = {0, 2027206421, 3221221104, 819826}
(gdb) p/x *(ul *)0xbfffee54@4
$39 = {0x0, 0x78d4b715, 0xbfffeef0, 0xc8272}
(gdb) p vs_top-vs_base
$40 = 3
(gdb) i reg a3
a3             0x79f114            0x79f114
(gdb) p vs_base
$41 = (object *) 0x79f114
(gdb) si
17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b04f4 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+516>:	addql #8,%sp
(gdb) i reg sp
sp             0xbfffed30          0xbfffed30
(gdb) si
0x023b04f6	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b04f6 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+518>:	tstl %a4
(gdb) i reg a4
a4             0xbfffee54          0xbfffee54
(gdb) si
0x023b04f8	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b04f8 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+520>:
    beqs 0x23b052c <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+572>
(gdb) si
0x023b04fa	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b04fa <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+522>:	cmpl %d3,%d2
(gdb) i reg d3
d3             0x79f120            7991584
(gdb) i reg d2
d2             0x79f118            7991576
(gdb) p _x
$42 = <optimized out>
(gdb) p vs_top
$43 = (object *) 0x79f120
(gdb) si
0x023b04fc	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b04fc <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+524>:
    bccw 0x23b08de <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+1518>
(gdb)
0x023b0500	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b0500 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+528>:	moveal %d2,%a1
(gdb) i reg d2
d2             0x79f118            7991576
(gdb) i reg a1
a1             0x4200000           0x4200000
(gdb) si
0x023b0502	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b0502 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+530>:	movel %a4,%d0
(gdb) i reg a4
a4             0xbfffee54          0xbfffee54
(gdb) i reg d0
d0             0x4355d20           70606112
(gdb) si
0x023b0504	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b0504 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+532>:	subql #4,%d0
(gdb) i reg d0
d0             0xbfffee54          -1073746348
(gdb) si
0x023b0506	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b0506 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+534>:	subl %a3,%d0
(gdb) i reg d0
d0             0xbfffee50          -1073746352
(gdb) i reg a3
a3             0x79f114            0x79f114
(gdb) si
0x023b0508	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b0508 <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+536>:
    movel %a1@+,%a1@(0,%d0:l)
(gdb) i reg d0
d0             0xbf85fd3c          -1081737924
(gdb) i reg a1
a1             0x79f118            0x79f118
(gdb) i reg d0
d0             0xbf85fd3c          -1081737924
(gdb) p *(ul *)0xbfffee54@4
$44 = {0, 2027206421, 3221221104, 819826}
(gdb) p/s *(ul *)0xbfffee54@4
$45 = {0, 2027206421, 3221221104, 819826}
(gdb) p/x *(ul *)0xbfffee54@4
$46 = {0x0, 0x78d4b715, 0xbfffeef0, 0xc8272}
(gdb) p *(ul *)0x79f118
$47 = 7704728
(gdb) p/x *(ul *)0x79f118
$48 = 0x759098
(gdb) si
0x023b050c	17163		V2083= ({register object _z=vs_base[0];register object *_x=vs_base+1,*_y=(object *)V2048;if (!_y) vs_top=base; else {for(;_x<vs_top;) *_y++=*_x++;if (_x>vs_top) _y--;vs_top=_y;}_z;});
1: x/i $pc
=> 0x23b050c <LI148__MAKE_FINAL_ACCESSOR_DFUN__pcl_dfun+540>:	cmpal %d3,%a1
(gdb) p/x *(ul *)0xbfffee54@4
$49 = {0x0, 0x759098, 0xbfffeef0, 0xc8272}
(gdb) q
=============================================================================

#1130962#10
Date:
2026-03-16 13:43:21 UTC
From:
To:
Hi Camm, please could you report that upstream?  Also maybe testing that
with trunk (gcc-16/gcc-snapshot?

Thanks, Matthias

#1130962#15
Date:
2026-03-16 16:39:37 UTC
From:
To:
Greetings!  The issue persists with gcc-16 and gcc-snapshot.  Will try
to file upstream.

Take care,

Matthias Klose <doko@debian.org> writes:

#1130962#20
Date:
2026-03-18 16:20:23 UTC
From:
To:
Greetings.  Filed upstream as Bug 124569.

Take care,

#1130962#25
Date:
2026-03-18 16:25:22 UTC
From:
To:
Control: forwarded -1 https://gcc.gnu.org/PR124569

thanks!