https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61713
--- Comment #2 from zhenqiang.chen at linaro dot org --- 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.