public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pavel.morozkin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/101063] New: #pragma STDC FENV_ACCESS ON: wrong code generation: instructions leading to side effects may not be generated
Date: Mon, 14 Jun 2021 11:10:50 +0000	[thread overview]
Message-ID: <bug-101063-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 101063
           Summary: #pragma STDC FENV_ACCESS ON: wrong code generation:
                    instructions leading to side effects may not be
                    generated
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pavel.morozkin at gmail dot com
  Target Milestone: ---

Bug-triggering code (t0.c):
#include <stdio.h>
#include <fenv.h>
#include <float.h>

#pragma STDC FENV_ACCESS ON

int main( void )
{
    volatile double d1 = DBL_MAX;
    volatile double d2 = DBL_MAX;

#ifdef __STDC__
    printf("__STDC__         %d\n", __STDC__);
#endif
#ifdef __STDC_VERSION__
    printf("__STDC_VERSION__ %ld\n", __STDC_VERSION__);
#endif
#ifdef __STDC_IEC_559__
    printf("__STDC_IEC_559__ %d\n", __STDC_IEC_559__);
#endif

    feclearexcept( FE_ALL_EXCEPT );
    ( void )( d1 * d2 );
    if  ( fetestexcept( FE_OVERFLOW ) )
    {
        return 0;
    }
    printf("error: no FE_OVERFLOW is raised\n");
    return 1;
}

Invocation: gcc t0.c -lm && ./a.out

Expected output:
__STDC__         1
__STDC_VERSION__ 201710
__STDC_IEC_559__ 1

Actual output:
__STDC__         1
__STDC_VERSION__ 201710
__STDC_IEC_559__ 1
error: no FE_OVERFLOW is raised

Note 1: Under -Wall gcc generates warning:
<source>:5: warning: ignoring '#pragma STDC FENV_ACCESS' [-Wunknown-pragmas]
    5 | #pragma STDC FENV_ACCESS ON

Note 2: Comparison with clang: https://godbolt.org/z/6GnqTYvaa.
Brief difference:
gcc:
        call    feclearexcept
        movsd   xmm0, QWORD PTR [rbp-8]
        movsd   xmm0, QWORD PTR [rbp-16]
        mov     edi, 8
        call    fetestexcept
clang:
        call    feclearexcept
        movsd   xmm0, qword ptr [rbp - 16]      # xmm0 = mem[0],zero
        movsd   xmm1, qword ptr [rbp - 24]      # xmm1 = mem[0],zero
        mulsd   xmm0, xmm1
        mov     edi, 8
        call    fetestexcept
Here we see that gcc does not generate "mulsd", which is a bug, because
execution of "mulsd" leads to side effects.

             reply	other threads:[~2021-06-14 11:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 11:10 pavel.morozkin at gmail dot com [this message]
2021-06-14 12:46 ` [Bug middle-end/101063] " glisse at gcc dot gnu.org
2021-06-14 19:06 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101063-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).