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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
With -O2 -fno-early-inlining it can be simplified:

#pragma pack(1)
struct S {
  signed : 31;
  unsigned f4 : 20;
};

static struct S global;

static struct S func_16(struct S *ptr) { return *ptr; }

int
main()
{
  struct S *local = &global;
  *local = func_16(local);
  return 0;
}

assembly:

main:
.LFB1:
        .cfi_startproc
        movl    global(%rip), %eax
        movl    %eax, -7(%rsp)
        movl    global+3(%rip), %eax
        movl    %eax, -4(%rsp)
        movl    -7(%rsp), %edx
        movl    %edx, -14(%rsp)
        movl    %eax, -11(%rsp)
        movl    -14(%rsp), %eax
        movl    %eax, global(%rip)  <--- this faults, global was promoted R/O
        xorl    %eax, %eax
        ret

note the #pragma pack is required to avoid optimizing everything away.

Reply via email to