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

            Bug ID: 128150
           Summary: __transaction_cancel does not roll back a struct
                    assignment from a const call at -O1 and above
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

struct S { int a; };
struct S g = {10};

__attribute__((transaction_safe, noinline)) struct S f(void)
{
  return (struct S){1};
}

int main(int argc, char **argv)
{
  __transaction_atomic {
    g = f();
    if (argc > 0)
      __transaction_cancel;
  }
  return g.a;
}

godbolt: https://godbolt.org/z/8Gd9Mhhc5

With no command-line arguments, __transaction_cancel must discard the
assignment to g, so main should return 10. With -fgnu-tm, -O1, -O2, -O3 and -Os
return 1 instead; -O0 or -O2 -fno-ipa-pure-const returns 10.

Reply via email to