public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104865] New: Wrong code for conditional expression on VAX
@ 2022-03-10 14:11 redi at gcc dot gnu.org
  2022-03-10 15:13 ` [Bug c++/104865] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-10 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104865
           Summary: Wrong code for conditional expression on VAX
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---
            Target: vax-dec-netbsdelf

This fails the second static assert on vax-dec-netbsdelf:


template<typename T>
constexpr int
cmp1(T x) noexcept
{
    int ix = (bool) __builtin_isnan(x);
    return ix;
}

template<typename T>
constexpr int
cmp2(T x) noexcept
{
    int ix = __builtin_isnan(x) ? 1 : 0;
    return ix;
}   

constexpr double nan = __builtin_nan("");

static_assert( cmp1(nan) ); 
static_assert( cmp2(nan) ); 

extern const auto c1 = cmp1(nan);
extern const auto c2 = cmp2(nan);     


$ gcc/cc1plus  -quiet ~/tmp/ord.C
/home/jwakely/tmp/ord.C:20:20: error: static assertion failed
   20 | static_assert( cmp2(nan) );
      |                ~~~~^~~~~





If the failing static assert is commented out, the assembly code is:

#NO_APP
        .file   "ord.C"
        .text
        .section        .rodata
        .align 2
        .type   _ZL3nan, @object
        .size   _ZL3nan, 8
_ZL3nan:
        .long   -32769
        .long   -1
.globl c1
        .align 2
        .type   c1, @object
        .size   c1, 4
c1:
        .long   1
.globl c2
        .align 2
        .type   c2, @object
        .size   c2, 4
c2:
        .zero   4
        .ident  "GCC: (GNU) 12.0.1 20220308 (experimental)"




For some reason the cmp2 function returns zero.



I'm using binutils configured with --target=vax-dec-netbsdelf and gcc
configured with:

/home/jwakely/src/gcc/configure --target vax-dec-netbsdelf --without-headers
--with-newlib --disable-bootstrap --disable-nls --without-lto --without-isl
--disable-libcc1 --disable-libsanitizer --disable-libitm --disable-libvtv
--disable-libgomp --disable-libssp --enable-languages=c++,c
--disable-libstdcxx-pch --disable-hosted-libstdcxx
--prefix=/home/jwakely/gcc/vax

I only did 'make all-gcc' and am running cc1plus from the build tree, as I
don't have a sysroot for the target.

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

* [Bug c++/104865] Wrong code for conditional expression on VAX
  2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
@ 2022-03-10 15:13 ` mpolacek at gcc dot gnu.org
  2022-03-11  0:48 ` [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-10 15:13 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org
   Last reconfirmed|                            |2022-03-10

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed with --target vax-dec-netbsdelf:

$ ./cc1plus -quiet 104865.C
104865.C:20:20: error: static assertion failed
   20 | static_assert( cmp2(nan) );
      |                ~~~~^~~~~

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

* [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math
  2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
  2022-03-10 15:13 ` [Bug c++/104865] " mpolacek at gcc dot gnu.org
@ 2022-03-11  0:48 ` pinskia at gcc dot gnu.org
  2022-04-02 13:57 ` macro at orcam dot me.uk
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-11  0:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Wrong code for conditional  |Wrong code for conditional
                   |expression on VAX           |expression on VAX or with
                   |                            |-ffast-math

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
/* Accessor macros for format properties.  */
#define MODE_HAS_NANS(MODE) \
  (FLOAT_MODE_P (MODE) && FLOAT_MODE_FORMAT (MODE)->has_nans)

.....
vax_f_format
...
false,

Hmm,
 -ffast-math has the same result (that is the assert happening) on any other
target really.

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

* [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math
  2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
  2022-03-10 15:13 ` [Bug c++/104865] " mpolacek at gcc dot gnu.org
  2022-03-11  0:48 ` [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math pinskia at gcc dot gnu.org
@ 2022-04-02 13:57 ` macro at orcam dot me.uk
  2022-04-02 14:51 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: macro at orcam dot me.uk @ 2022-04-02 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

Maciej W. Rozycki <macro at orcam dot me.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |macro at orcam dot me.uk

--- Comment #3 from Maciej W. Rozycki <macro at orcam dot me.uk> ---
Should `__builtin_nan' even compile on non-IEEE-754 FP targets?

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

* [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math
  2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-04-02 13:57 ` macro at orcam dot me.uk
@ 2022-04-02 14:51 ` redi at gcc dot gnu.org
  2022-04-02 16:00 ` macro at orcam dot me.uk
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-02 14:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
They can still have NaNs.

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

* [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math
  2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-04-02 14:51 ` redi at gcc dot gnu.org
@ 2022-04-02 16:00 ` macro at orcam dot me.uk
  2022-04-02 16:07 ` redi at gcc dot gnu.org
  2022-04-02 16:37 ` macro at orcam dot me.uk
  6 siblings, 0 replies; 8+ messages in thread
From: macro at orcam dot me.uk @ 2022-04-02 16:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Maciej W. Rozycki <macro at orcam dot me.uk> ---
Wrong question then.  Should `__builtin_nan' even compile on non-IEEE-754
FP targets that don't have a qNaN?  And I'll reply to myself.

According to our manual:

"-- Built-in Function: double __builtin_nan (const char *str)
     This is an implementation of the ISO C99 function 'nan'."

and then according to ISO C99:

"The nan functions return a quiet NaN, if available, with content
indicated through tagp.  If the implementation does not support quiet
NaNs, the functions return zero."

so firstly __builtin_isnan(__builtin_nan("")) is supposed to return 0
with the VAX target (because obviously 0.0 is not a NaN), and secondly
the compiled program is wrong as `_ZL3nan' is supposed to be set to
all-zeros (which is the representation of 0.0 datum with the VAX
floating-point format), and then `c1' and `c2' must likewise be both 0.

Both asserts are supposed to fail with the VAX target then (and similarly
PDP-11, which has a similar FP format).

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

* [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math
  2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-04-02 16:00 ` macro at orcam dot me.uk
@ 2022-04-02 16:07 ` redi at gcc dot gnu.org
  2022-04-02 16:37 ` macro at orcam dot me.uk
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-02 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
OK, maybe I should not have used __builtin_nan in the test. The bug is in the
rest of the code though, isn't it? Replace the __builtin_nan with a function
returning the same sNaN, does the test still fail? (I can't check myself right
now).

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

* [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math
  2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-04-02 16:07 ` redi at gcc dot gnu.org
@ 2022-04-02 16:37 ` macro at orcam dot me.uk
  6 siblings, 0 replies; 8+ messages in thread
From: macro at orcam dot me.uk @ 2022-04-02 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Maciej W. Rozycki <macro at orcam dot me.uk> ---
Well, it's not clear to me whether the reserved operand as defined by the
VAX floating-point architecture ought be considered an sNaN given that
there is no qNaN.

Also a reserved operand causes a fault with any FP instruction, even data
moves (though one can move a reserved operand bit pattern with an integer
move of the right width, observing that there is a single register file
for both integer and FP arithmetic, and that of course FP operations can
be directly performed on memory as well).

In any case there's probably more than one bug here.

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

end of thread, other threads:[~2022-04-02 16:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 14:11 [Bug c++/104865] New: Wrong code for conditional expression on VAX redi at gcc dot gnu.org
2022-03-10 15:13 ` [Bug c++/104865] " mpolacek at gcc dot gnu.org
2022-03-11  0:48 ` [Bug c++/104865] Wrong code for conditional expression on VAX or with -ffast-math pinskia at gcc dot gnu.org
2022-04-02 13:57 ` macro at orcam dot me.uk
2022-04-02 14:51 ` redi at gcc dot gnu.org
2022-04-02 16:00 ` macro at orcam dot me.uk
2022-04-02 16:07 ` redi at gcc dot gnu.org
2022-04-02 16:37 ` macro at orcam dot me.uk

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