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

            Bug ID: 128163
           Summary: wrong code at -O1: store through the pointer argument
                    of an [[unsequenced]] function declared without a
                    prototype is ignored
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yuki.tanaka at defaultcase dot de
  Target Milestone: ---

int a() [[unsequenced]];

__attribute__((noipa)) int a(int *x)
{
  *x = 5;
  return 1;
}

int main(void)
{
  int v = 0;

  a(&v);
  if (v != 5)
    __builtin_abort();
  return 0;
}

Compiler Explorer:
ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 134
Program terminated with signal SIGABRT (6)

The definition of a has the pointer parameter x, and an unsequenced function
may modify an object through a pointer parameter. a(&v) stores 5 to v, so v
must be 5 after the call and the program must exit with 0, as it does at -O0.
Instead GCC assumes that v is still 0 after the call and main aborts.

https://godbolt.org/z/WYfK78jPr

Also fails at -O1, with [[reproducible]] and with __attribute__((unsequenced)).
With the prototype int a(int *) [[unsequenced]]; the program exits with 0.

Reply via email to