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

            Bug ID: 111088
           Summary: useless 'xor eax,eax' inserted when a value is not
                    returned.
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: charly.poyac at gmail dot com
  Target Milestone: ---

I compile this simple C code with GCC 13.2:

int foo(int *a)
{
    *a += 1;
}

int foo2(int *a)
{
    *a += 1;
} 

and it produces the following assembly code with '-O3':

foo:
        add     DWORD PTR [rdi], 1
        ret
foo2:
        add     DWORD PTR [rdi], 1
        xor     eax, eax
        ret

see godbolt: https://godbolt.org/z/eeT63ePcr

We can see the inconsistency between the two functions with the 'xor eax,eax'
added in foo2. This does not happen if I compile with -O1.

Yes, these functions should return an integer, but they don't. However, this is
allowed by the C standard (2018 6.9.1 11/12).

Reply via email to