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.