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

            Bug ID: 114768
           Summary: Volatile reads can be optimized away
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bouanto at zoho dot com
  Target Milestone: ---

In the following code:

void test(int *ptr) {
    *ptr = *(volatile int *)ptr;
}

The volatile read is optimized away and GCC produces the following asm:

test(int*):
        ret

Godbolt link: https://gcc.godbolt.org/z/rabToGfqj

Clang produces the following code:

test(int*):                              # @test(int*)
        mov     eax, dword ptr [rdi]
        ret

which is likely to be the expected behavior.

Reply via email to