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.
This ICE also happened on the trunk.
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.
*** Bug 61756 has been marked as a duplicate of this bug. ***
I'll take it.
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
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
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
This has been fixed on trunk and 4.9
*** Bug 56964 has been marked as a duplicate of this bug. ***