From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CCFB93858D3C; Wed, 1 Sep 2021 00:56:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCFB93858D3C From: "jeremy-gcc-bugzilla at sawicki dot us" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/102150] New: Speculative execution of inline assembly causes divide error Date: Wed, 01 Sep 2021 00:56:26 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jeremy-gcc-bugzilla at sawicki dot us X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Sep 2021 00:56:26 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102150 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=3D51391&action=3Dedit Reproducible test case The attached test case uses inline assembly to wrap the x86_64 DIV instruct= ion. 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 discard= ed 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=3D82677 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=3D93491 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=3D/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=