https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109166
Bug ID: 109166
Summary: Built-in __atomic_test_and_set does not seem to be
atomic on ARMv4T
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: jdx at o2 dot pl
Target Milestone: ---
Host: x86_64-w64-mingw32
Target: arm-eabi
For the following source code:
bool tas(unsigned char *ptr)
{
return __atomic_test_and_set(ptr, __ATOMIC_SEQ_CST);
}
gcc -march=armv4t -marm -O3 -Wall -Wextra gives:
tas:
mov r3, r0
mov r2, #1
ldrb r0, [r0] @ zero_extendqisi2
strb r2, [r3]
bx lr
I am not an ARM assembler expert, but I think that LDRB/STRB pair should be
replaced with SWPB as shown here: https://godbolt.org/z/116MbYK79.
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107567.