public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned.
@ 2023-08-21 10:09 charly.poyac at gmail dot com
  2023-08-21 13:59 ` [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: charly.poyac at gmail dot com @ 2023-08-21 10:09 UTC (permalink / raw)
  To: gcc-bugs

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).

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-23 12:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21 10:09 [Bug c/111088] New: useless 'xor eax,eax' inserted when a value is not returned charly.poyac at gmail dot com
2023-08-21 13:59 ` [Bug middle-end/111088] useless 'xor eax,eax' inserted when a value is not returned and icf pinskia at gcc dot gnu.org
2023-08-21 16:23 ` pinskia at gcc dot gnu.org
2023-08-21 16:27   ` Jan Hubicka
2023-08-21 16:27 ` [Bug ipa/111088] " hubicka at ucw dot cz
2023-08-22  6:49 ` rguenth at gcc dot gnu.org
2023-08-23 12:29 ` jamborm at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).