public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/101063] New: #pragma STDC FENV_ACCESS ON: wrong code generation: instructions leading to side effects may not be generated
@ 2021-06-14 11:10 pavel.morozkin at gmail dot com
  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
  0 siblings, 2 replies; 3+ messages in thread
From: pavel.morozkin at gmail dot com @ 2021-06-14 11:10 UTC (permalink / raw)
  To: gcc-bugs

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.

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

* [Bug middle-end/101063] #pragma STDC FENV_ACCESS ON: wrong code generation: instructions leading to side effects may not be generated
  2021-06-14 11:10 [Bug middle-end/101063] New: #pragma STDC FENV_ACCESS ON: wrong code generation: instructions leading to side effects may not be generated pavel.morozkin at gmail dot com
@ 2021-06-14 12:46 ` glisse at gcc dot gnu.org
  2021-06-14 19:06 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: glisse at gcc dot gnu.org @ 2021-06-14 12:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
> Note 1: Under -Wall gcc generates warning:
> <source>:5: warning: ignoring '#pragma STDC FENV_ACCESS' [-Wunknown-pragmas]

That seems like a huge hint, this is not implemented in gcc. You can find
several existing PR in this bugzilla.

There is a branch refs/users/glisse/heads/fenv that was kind of functional last
time I tried, but I'll never have time to polish it.

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

* [Bug middle-end/101063] #pragma STDC FENV_ACCESS ON: wrong code generation: instructions leading to side effects may not be generated
  2021-06-14 11:10 [Bug middle-end/101063] New: #pragma STDC FENV_ACCESS ON: wrong code generation: instructions leading to side effects may not be generated pavel.morozkin at gmail dot com
  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
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-14 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 29186 (and others).

*** This bug has been marked as a duplicate of bug 29186 ***

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

end of thread, other threads:[~2021-06-14 19:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14 11:10 [Bug middle-end/101063] New: #pragma STDC FENV_ACCESS ON: wrong code generation: instructions leading to side effects may not be generated pavel.morozkin at gmail dot com
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

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