https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127492

            Bug ID: 127492
           Summary: wrong code with __atomic_add_fetch
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---

### Reproducer

#include <stdio.h>
#include <stdatomic.h>

__int128 v = 1;

int
main (void)
{
  __int128 r = __atomic_add_fetch (&v, v, __ATOMIC_RELAXED);

  printf ("r=%llu v=%llu\n",
          (unsigned long long) r, (unsigned long long) v);
  return 0;
}

Output:
$ gcc -O0 -latomic
$ ./a.out
r=2 v=2
$ gcc -O1 -latomic
r=3 v=2

Reproduced with any optimization level, any GCC version, even in 4.9.0, which
is the oldest version I can test.

Reply via email to