Bug 61713 - ICE when building c++ code with atomic functions for thumb1 target
Summary: ICE when building c++ code with atomic functions for thumb1 target
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Kyrill Tkachov
URL:
Keywords: ice-on-valid-code
: 56964 61756 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-07-04 06:40 UTC by wangzheyu
Modified: 2021-11-29 07:32 UTC (History)
3 users (show)

See Also:
Host:
Target: arm-none-eabi
Build:
Known to work:
Known to fail: 4.9.0, 5.0
Last reconfirmed: 2014-07-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wangzheyu 2014-07-04 06:40:09 UTC
The tool chain is built from:
gcc version 4.9.1 20140630 (prerelease) [gcc-4_9-branch revision 212159]
when compile below code, there will be ICE.
int main()
{
  typedef bool atomic_type;
  atomic_type c1;
  atomic_type c2;
  atomic_type c3(0);
  __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
  __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
                              __ATOMIC_RELAXED);
  __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
  __atomic_load_n(&c1, __ATOMIC_RELAXED);

  return 0;
}
Remember to save it as a c++ source file. For the debuggabe gcc, the ICE is:
at1.cpp: In function 'int main()':
at1.cpp:12:47: internal compiler error: in emit_move_insn, at expr.c:3609
__atomic_test_and_set(&c1, __ATOMIC_RELAXED);
^
0x83c8240 emit_move_insn(rtx_def*, rtx_def*)
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/expr.c:3608
0x850f85d expand_atomic_test_and_set(rtx_def*, rtx_def*, memmodel)
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/optabs.c:7337
0x82ee779 expand_builtin_atomic_test_and_set
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/builtins.c:5552
0x82ee779 expand_builtin(tree_node*, rtx_def*, rtx_def*, machine_mode, int)
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/builtins.c:6781
0x83c3382 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/expr.c:10327
0x830bd38 expand_expr
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/expr.h:457
0x830bd38 expand_call_stmt
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/cfgexpand.c:2275
0x830bd38 expand_gimple_stmt_1
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/cfgexpand.c:3170
0x830bd38 expand_gimple_stmt
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/cfgexpand.c:3322
0x830c896 expand_gimple_basic_block
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/cfgexpand.c:5162
0x830ebae gimple_expand_cfg
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/cfgexpand.c:5741
0x830ebae execute
/home/build/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/src/gcc/gcc/cfgexpand.c:5961
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.
For the release version gcc, the ICE is:
build@build-desktop:~/temp/gcc-arm-none-eabi-4_9-2014q3-20140701/case$ ../install-native/bin/arm-none-eabi-g++ -mthumb -O0 at1.cpp -S
at1.cpp: In function 'int main()':
at1.cpp:12:47: internal compiler error: in emit_move_insn, at expr.c:3609
__atomic_test_and_set(&c1, __ATOMIC_RELAXED);
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 wangzheyu 2014-07-04 07:07:32 UTC
This ICE also happened on the trunk.
Comment 2 zhenqiang.chen 2014-07-04 07:46:58 UTC
Root cause:

When expand_call_stmt, if gimple_call_lhs (stmt) is NULL, it will set target to const0_rtx.

Then when expand_atomic_test_and_set, it tries to emit_move_insn (subtarget, mem). Moving a value to const0_rtx is defintely illegal.

From the context, we can see const0_rtx means no return value. In this case, no need to emit_move_insn (subtarget, mem). I will work out a patch to check subtarget.
Comment 3 ktkachov 2014-07-10 08:09:41 UTC
*** Bug 61756 has been marked as a duplicate of this bug. ***
Comment 4 ktkachov 2014-07-10 08:10:56 UTC
I'll take it.
Comment 5 ktkachov 2014-08-04 10:04:04 UTC
Author: ktkachov
Date: Mon Aug  4 10:03:32 2014
New Revision: 213555

URL: https://gcc.gnu.org/viewcvs?rev=213555&root=gcc&view=rev
Log:
PR 61713: ICE when expanding single-threaded version of atomic_test_and_set.

	PR target/61713
	* gcc/optabs.c (expand_atomic_test_and_set): Do not try to emit
	move to subtarget in serial version if result is ignored.

	PR target/61713
	* gcc.dg/pr61756.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr61756.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/optabs.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Yvan Roux 2014-08-10 23:03:47 UTC
Author: yroux
Date: Sun Aug 10 23:03:16 2014
New Revision: 213801

URL: https://gcc.gnu.org/viewcvs?rev=213801&root=gcc&view=rev
Log:
gcc/
2014-08-11 Yvan Roux  <yvan.roux@linaro.org>

	Backport from trunk r213555.
	2014-08-04  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

	PR target/61713
	* gcc/optabs.c (expand_atomic_test_and_set): Do not try to emit
	move to subtarget in serial version if result is ignored.

gcc/testsuite
2014-08-11 Yvan Roux  <yvan.roux@linaro.org>
	Backport from trunk r213555.
	2014-08-04  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

	PR target/61713
	* gcc.dg/pr61756.c: New test.


Added:
    branches/linaro/gcc-4_9-branch/gcc/testsuite/gcc.dg/pr61756.c
Modified:
    branches/linaro/gcc-4_9-branch/gcc/ChangeLog.linaro
    branches/linaro/gcc-4_9-branch/gcc/optabs.c
    branches/linaro/gcc-4_9-branch/gcc/testsuite/ChangeLog.linaro
Comment 7 ktkachov 2014-08-14 09:32:49 UTC
Author: ktkachov
Date: Thu Aug 14 09:32:17 2014
New Revision: 213954

URL: https://gcc.gnu.org/viewcvs?rev=213954&root=gcc&view=rev
Log:
[optabs.c] Fix ICE when expanding single-threaded version of atomic_test_and_set

	Backport from mainline
	2014-08-04  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

	PR target/61713
	* gcc/optabs.c (expand_atomic_test_and_set): Do not try to emit
	move to subtarget in serial version if result is ignored.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/pr61756.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/optabs.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Comment 8 ktkachov 2014-10-16 16:18:03 UTC
This has been fixed on trunk and 4.9
Comment 9 Andrew Pinski 2021-11-29 07:32:24 UTC
*** Bug 56964 has been marked as a duplicate of this bug. ***