Bug 61544 - ICE due to thumb1_reorg function mishandles label type insn
Summary: ICE due to thumb1_reorg function mishandles label type insn
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 4.9.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 61712 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-06-18 04:32 UTC by Terry Guo
Modified: 2015-01-31 15:44 UTC (History)
2 users (show)

See Also:
Host:
Target: arm
Build:
Known to work:
Known to fail: 4.9.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Terry Guo 2014-06-18 04:32:19 UTC
When build some c++ files for pure thumb1 target, I ran into below ICE:

terguo01@terry-pc01:thumb1-reorg$ /myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/./gcc/xgcc -shared-libgcc -B/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/./gcc -nostdinc++ -L/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/arm-none-eabi/libstdc++-v3/src -L/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/arm-none-eabi/libstdc++-v3/src/.libs -L/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/arm-none-eabi/libstdc++-v3/libsupc++/.libs -B/myssd/terguo01/toolchain-build/thumb1-reorg/install-native/arm-none-eabi/bin/ -B/myssd/terguo01/toolchain-build/thumb1-reorg/install-native/arm-none-eabi/lib/ -isystem /myssd/terguo01/toolchain-build/thumb1-reorg/install-native/arm-none-eabi/include -isystem /myssd/terguo01/toolchain-build/thumb1-reorg/install-native/arm-none-eabi/sys-include -I/myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/libstdc++-v3/../libgcc -I/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/arm-none-eabi/libstdc++-v3/include/arm-none-eabi -I/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/arm-none-eabi/libstdc++-v3/include -I/myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/libstdc++-v3/libsupc++ -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -frandom-seed=sstream-inst.lo -g -O2 -c /myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/libstdc++-v3/src/c++98/sstream-inst.cc -o sstream-inst.o 
In file included from /myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/libstdc++-v3/src/c++98/sstream-inst.cc:29:0:
/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/arm-none-eabi/libstdc++-v3/include/sstream: In member function 'std::basic_stringstream<_CharT, _Traits, _Alloc>::__string_type std::basic_stringstream<_CharT, _Traits, _Alloc>::str() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_stringstream<_CharT, _Traits, _Alloc>::__string_type = std::basic_string<char>]':
/myssd/terguo01/toolchain-build/thumb1-reorg/build-native/gcc-final/arm-none-eabi/libstdc++-v3/include/sstream:584:36: internal compiler error: Segmentation fault
       { return _M_stringbuf.str(); }
                                    ^
0xd90226 crash_signal
	/myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/gcc/toplev.c:337
0x10e1219 thumb1_reorg
	/myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/gcc/config/arm/arm.c:16954
0x10e1cbe arm_reorg
	/myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/gcc/config/arm/arm.c:17223
0xd1451c execute
	/myssd/terguo01/toolchain-build/thumb1-reorg/src/gcc/gcc/reorg.c:3959
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

Such ICE is triggered when apply thumb1_reorg function to below basic block:

(gdb) p debug_bb(bb)
(code_label/s 477 953 480 736 "" [1 uses])
(note 480 477 954 [bb 19] NOTE_INSN_BASIC_BLOCK)
(note 954 480 955 (var_location this (plus:SI (reg/f:SI 103 afp)
    (const_int -20 [0xffffffffffffffec]))) NOTE_INSN_VAR_LOCATION)
(note 955 954 956 (var_location this (plus:SI (reg/f:SI 103 afp)
    (const_int -20 [0xffffffffffffffec]))) NOTE_INSN_VAR_LOCATION)

For the code_label insn 477, its INSN_CODE accidentally equals the value of CODE_FOR_cbranchsi4_insn. This leads to the execution of subsequent gcc code:

16953	      pat = PATTERN (insn);
16954	      op0 = XEXP (XEXP (SET_SRC (pat), 0), 0);

Then the ICE is triggered due to applying SET_SRC to a code_label insn.

From the very beginning, we shouldn't use INSN_CODE to insn like code_label. Thus when the head of basic block isn't a proper insn, we should move to next basic block.

Patch at https://gcc.gnu.org/ml/gcc-patches/2014-06/msg00809.html can fix this ICE.
Comment 1 xuepeng guo 2014-06-18 10:11:41 UTC
Author: xguo
Date: Wed Jun 18 10:11:08 2014
New Revision: 211775

URL: https://gcc.gnu.org/viewcvs?rev=211775&root=gcc&view=rev
Log:
2014-06-18  Terry Guo  <terry.guo@arm.com>

	PR target/61544
	* config/arm/arm.c (thumb1_reorg): Move to next basic block if we
	reach the head.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.c
Comment 2 Terry Guo 2014-06-18 10:13:07 UTC
The fix is submitted.
Comment 3 zqchen 2014-07-09 05:27:49 UTC
Author: zqchen
Date: Wed Jul  9 05:27:16 2014
New Revision: 212385

URL: https://gcc.gnu.org/viewcvs?rev=212385&root=gcc&view=rev
Log:
	Backport r211775 from trunk.
	2014-06-18  Terry Guo  <terry.guo@arm.com>

	PR target/61544
	* config/arm/arm.c (thumb1_reorg): Move to next basic block if we
	reach the head.


Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/config/arm/arm.c
Comment 4 Richard Earnshaw 2014-07-29 10:50:18 UTC
*** Bug 61712 has been marked as a duplicate of this bug. ***