https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84292
Bug ID: 84292 Summary: __sync_add_and_fetch returns the old value instead of the new value Product: gcc Version: 5.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgcc Assignee: unassigned at gcc dot gnu.org Reporter: maryse.levavasseur at stormshield dot eu Target Milestone: --- Created attachment 43378 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43378&action=edit proposed patch I am using gcc5.4.0 on ARMv5 and FreeBSD 10.3 and __sync_add_and_fetch returns the old value of the first argument while I expect the new value. #include <stdio.h> int main(void) { unsigned int var = 1; printf("%u\n", __sync_add_and_fetch(&var, 1)); return 0; } ==> This displays 1 on ARMv5 and 2 on the other platforms (still on FreeBSD 10.3) In the source file libgcc/config/arm/freebsd-atomic.c, the source code of __sync_##NAME##_and_fetch_##N is exactly the same as __sync_fetch_and_##NAME##_##N You can find attached a proposed patch for this problem. $ gcc5 -v Using built-in specs. COLLECT_GCC=gcc5 COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc5/gcc/arm-portbld-freebsd10.3/5.4.0/lto-wrapper Target: arm-portbld-freebsd10.3 Configured with: ../gcc-5.4.0/configure --disable-multilib --with-build-config=bootstrap-debug --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc5 --libexecdir=/usr/local/libexec/gcc5 --program-suffix=5 --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc5/include/c++/ --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --disable-libgcj --enable-languages=c,c++ --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/info/gcc5 --target=arm-portbld-freebsd10.3 --disable-lto Thread model: posix gcc version 5.4.0 (FreeBSD Ports Collection)