public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/102150] New: Speculative execution of inline assembly causes divide error
@ 2021-09-01  0:56 jeremy-gcc-bugzilla at sawicki dot us
  2021-09-01  8:41 ` [Bug inline-asm/102150] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: jeremy-gcc-bugzilla at sawicki dot us @ 2021-09-01  0:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102150
           Summary: Speculative execution of inline assembly causes divide
                    error
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeremy-gcc-bugzilla at sawicki dot us
  Target Milestone: ---

Created attachment 51391
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51391&action=edit
Reproducible test case

The attached test case uses inline assembly to wrap the x86_64 DIV instruction.
 GCC speculatively executes the inline assembly on inputs that the source
program does not, resulting in a divide error.

The GCC documentation says that non-volatile inline assembly may be discarded
or moved out of loops.  It is not obvious whether speculative execution is also
permitted.  I asked on gcc-help and was asked to file a report.

A related report points out that many projects currently wrap the DIV
instruction without using volatile:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82677

Another related report considers the similar issue of whether pure/const
functions must be non-trapping for inputs they don't actually receive:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93491

If it is determined that volatile is required, it would helpful to clarify in
the documentation that speculative execution may occur without volatile:
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile

gcc version 11.2.0 (GCC)
Target: x86_64-pc-linux-gnu
Configured with: /home/jeremys/gcc-11.2.0/configure
--prefix=/home/jeremys/gcc-11.2.0-install --disable-multilib

Command line: g++ -O3 -o divasm divasm.cpp
No compiler errors/warnings are produced
When executed, a divide error occurs

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

end of thread, other threads:[~2021-09-01  8:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  0:56 [Bug rtl-optimization/102150] New: Speculative execution of inline assembly causes divide error jeremy-gcc-bugzilla at sawicki dot us
2021-09-01  8:41 ` [Bug inline-asm/102150] " rguenth 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).