Bug 91702

Summary: [9/10 Regression] ICE with mips16
Product: gcc Reporter: Hauke Mehrtens <gcc>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: jakub, slyich
Priority: P3    
Version: 9.2.0   
Target Milestone: 9.3   
URL: https://bugs.openwrt.org/index.php?do=details&task_id=2455
Host: mips-openwrt-linux Target: mips-openwrt-linux
Build: x86_64-pc-linux-gnu Known to work: 8.3.0
Known to fail: 9.2.0 Last reconfirmed:

Description Hauke Mehrtens 2019-09-08 18:02:08 UTC
I am getting the following internal compiler error when building json-c-0.13.1 with GCC 9.2 for MIPS big endian with mip16 support.

--------
$ make V=s
make  all-recursive
make[1]: Entering directory '/home/hauke/openwrt/dl/tmp/json-c-0.13.1'
Making all in .
make[2]: Entering directory '/home/hauke/openwrt/dl/tmp/json-c-0.13.1'
/bin/sh ./libtool  --tag=CC   --mode=compile mips-openwrt-linux-gcc -DHAVE_CONFIG_H -I.     -mips16  -Wall -Werror -Wcast-qual -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -D_GNU_SOURCE -D_REENTRANT -MT json_object.lo -MD -MP -MF .deps/json_object.Tpo -c -o json_object.lo json_object.c
libtool: compile:  mips-openwrt-linux-gcc -DHAVE_CONFIG_H -I. -mips16 -Wall -Werror -Wcast-qual -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -D_GNU_SOURCE -D_REENTRANT -MT json_object.lo -MD -MP -MF .deps/json_object.Tpo -c json_object.c  -fPIC -DPIC -o .libs/json_object.o
during RTL pass: mach
json_object.c: In function 'json_object_int_inc':
json_object.c:735:1: internal compiler error: Segmentation fault
  735 | }
      | ^
0xa1397f crash_signal
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/toplev.c:326
0xcd428e mips_split_move(rtx_def*, rtx_def*, mips_split_type, rtx_def*)
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/config/mips/mips.c:4871
0xe9cc20 gen_split_59(rtx_insn*, rtx_def**)
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/config/mips/mips.md:5248
0xeec295 split_3
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/config/mips/mips.md:5246
0xeec295 split_insns(rtx_def*, rtx_insn*)
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/config/mips/mips.md:7019
0x72b189 try_split(rtx_def*, rtx_insn*, int)
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/emit-rtl.c:3851
0x9843d1 split_insn
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/recog.c:2901
0x988f67 split_all_insns_noflow()
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/recog.c:3063
0xccb594 mips16_lay_out_constants
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/config/mips/mips.c:17505
0xcd1765 mips_reorg
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/config/mips/mips.c:19380
0x9b1789 execute
	/home/hauke/openwrt/openwrt/build_dir/toolchain-mips_24kc_gcc-9.2.0_musl/gcc-9.2.0/gcc/reorg.c:3992
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://bugs.openwrt.org/> for instructions.
make[2]: *** [Makefile:587: json_object.lo] Error 1
make[2]: Leaving directory '/home/hauke/openwrt/dl/tmp/json-c-0.13.1'
make[1]: *** [Makefile:651: all-recursive] Error 1
make[1]: Leaving directory '/home/hauke/openwrt/dl/tmp/json-c-0.13.1'
make: *** [Makefile:448: all] Error 2
---------

The problem is happening in this code part:
https://github.com/json-c/json-c/blob/json-c-0.13.1-20180305/json_object.c#L735

I can reproduce it by using configure with these commands:
CFLAGS="-mips16 " ./configure --target=mips-openwrt-linux --host=mips-openwrt-linux --build=x86_64-pc-linux-gnu

and then run make

When I remove the -mips16 option from CFLAGS it compiles without an ICE.

I am using GCC 9.2.0 from OpenWrt master as of today with the following patches applied:
https://git.openwrt.org/?p=openwrt/openwrt.git;a=tree;f=toolchain/gcc/patches/9.2.0;h=81caffc170b7604a685785db350fa5b5e72baf63;hb=HEAD

This was freshly compiled on a Arch Linux system which also uses GCC 9.2.0 as system compiler.
OpenWrt uses binutils 2.32

I haven't seen this problem with GCC 7.4.0 and GCC 8.3.0, I am also not aware of any such bug report in OpenWrt.

This is the OpenWrt configuration to reproduce this problem:
------------------
[hauke@hauke-arch openwrt]$ ./scripts/diffconfig.sh 
CONFIG_TARGET_lantiq=y
CONFIG_TARGET_lantiq_xrx200=y
CONFIG_TARGET_lantiq_xrx200_Default=y
CONFIG_DEVEL=y
CONFIG_TOOLCHAINOPTS=y
# CONFIG_BINUTILS_USE_VERSION_2_31_1 is not set
CONFIG_BINUTILS_USE_VERSION_2_32=y
CONFIG_BINUTILS_VERSION="2.32"
CONFIG_BINUTILS_VERSION_2_32=y
CONFIG_GCC_USE_EMBEDDED_PATH_REMAP=y
# CONFIG_GCC_USE_VERSION_7 is not set
CONFIG_GCC_USE_VERSION_9=y
CONFIG_GCC_VERSION="9.2.0"
CONFIG_GCC_VERSION_9=y
--------------------------

This was initially reported here:
https://bugs.openwrt.org/index.php?do=details&task_id=2455
Comment 1 Dragan Mladjenovic 2019-09-18 07:54:31 UTC
Hi,

Same as with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91474#c5. Chould you perhaps verify if r273174 fixes your issue?

Thanks in advance.
Comment 2 Hauke Mehrtens 2019-09-19 18:51:39 UTC
I backported https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=273174 on top of GCC 9.2.0 and I do not see this problem any more, OpenWrt compiles now file with these settings. Please backport this change to the gcc 9 branch.
Comment 3 draganm 2019-10-04 10:58:19 UTC
Author: draganm
Date: Fri Oct  4 10:57:48 2019
New Revision: 276569

URL: https://gcc.gnu.org/viewcvs?rev=276569&root=gcc&view=rev
Log:
Backprot fix for uninitialised use in mips_split_move

Fixes PR target/91474 and PR target/91702.

2019-10-04  Dragan Mladjenovic  <dmladjenovic@wavecomp.com>

	Backport from mainline
	2019-07-07  Richard Sandiford  <richard.sandiford@arm.com>

	gcc/
		* config/mips/mips.c (mips_split_move): Zero-initialize addr
		and check whether addr.reg is nonnull before using it.

Modified:
    branches/gcc-9-branch/gcc/ChangeLog
    branches/gcc-9-branch/gcc/config/mips/mips.c
Comment 4 Jakub Jelinek 2019-11-20 17:23:25 UTC
So fixed for 9.3+ and can be closed then?
Comment 5 Dragan Mladjenovic 2019-11-20 19:46:44 UTC
Yes, I believe so.
Comment 6 Jakub Jelinek 2019-11-20 20:04:33 UTC
.