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

            Bug ID: 110516
           Summary: core.volatile.volatileLoad is broken
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: witold.baryluk+gcc at gmail dot com
  Target Milestone: ---

gcc 12.2.0 (from Debian stable) and gcc trunk 14.0.0 (in godbolt) tested.

core.volatile.volatileLoad simply does not work.

1) It merges loads.
2) It removes unused loads at -O1 and higher.

Example:

void actualRun(ubyte* ptr1) {
  import core.volatile : volatileLoad;
  volatileLoad(ptr1);
  volatileLoad(ptr1);
  volatileLoad(ptr1);
  volatileLoad(ptr1);
}


Without optimisations:

void example.actualRun(ubyte*):
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-8], rdi
        nop
        pop     rbp
        ret


Incorrect.



With optimisations:

void example.actualRun(ubyte*):
        ret

Incorrect.


Expected:

void example.actualRun(ubyte*):
        movzx   eax, byte ptr [rdi]
        movzx   eax, byte ptr [rdi]
        movzx   eax, byte ptr [rdi]
        movzx   eax, byte ptr [rdi]
        ret



dmd and ldc behave properly.


It looks like it never worked properly.

Would be good to have a test case for this, so it does not become a regression
later.


I did not test volatileStore, but I would not be surprised it is also broken.

Reply via email to