public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104971] New: Optimisation for __builtin_ia32_readeflags corrupts the stack
@ 2022-03-17 18:49 andrew.cooper3 at citrix dot com
  2022-03-17 19:05 ` [Bug middle-end/104971] [9/10/11/12 Regression] " jakub at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: andrew.cooper3 at citrix dot com @ 2022-03-17 18:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104971
           Summary: Optimisation for __builtin_ia32_readeflags corrupts
                    the stack
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrew.cooper3 at citrix dot com
  Target Milestone: ---

Full example: https://godbolt.org/z/xGq3c4Mnc

Given:

int broken(void)
{
    int fl = __builtin_ia32_readeflags_u64();
}

gcc -O2 generates:

broken:
        pushfq
        ret

Which is going explode very quickly.

Code generation appears to be safe without optimisation, but even -O alone is
enough to create problems.

At a guess, the optimiser has concluded that the result is unused, drops the
`pop %reg`, but fails to also drop the `pushf` too.

Looking through history on Godbolt, it appears that GCC 4.9 (which introduced
this builtin) has correct optimised code generation, and it regressed between
4.9 and 5.1.

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

end of thread, other threads:[~2022-05-11  6:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-17 18:49 [Bug middle-end/104971] New: Optimisation for __builtin_ia32_readeflags corrupts the stack andrew.cooper3 at citrix dot com
2022-03-17 19:05 ` [Bug middle-end/104971] [9/10/11/12 Regression] " jakub at gcc dot gnu.org
2022-03-17 19:35 ` jakub at gcc dot gnu.org
2022-03-17 20:49 ` andrew.cooper3 at citrix dot com
2022-03-17 21:12 ` mpolacek at gcc dot gnu.org
2022-03-18 17:32 ` jakub at gcc dot gnu.org
2022-03-19 12:53 ` cvs-commit at gcc dot gnu.org
2022-03-25 16:31 ` [Bug middle-end/104971] [9/10/11 " cvs-commit at gcc dot gnu.org
2022-03-29  5:54 ` cvs-commit at gcc dot gnu.org
2022-03-30  8:17 ` [Bug middle-end/104971] [9/10 " jakub at gcc dot gnu.org
2022-05-10  8:25 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:25 ` cvs-commit 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).