* [Bug c++/98216] [C++20] std::array<double, N> template parameter error with negative values
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
@ 2020-12-09 16:04 ` redi at gcc dot gnu.org
2020-12-10 7:33 ` rguenth at gcc dot gnu.org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-09 16:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-12-09
Ever confirmed|0 |1
Keywords| |wrong-code
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] std::array<double, N> template parameter error with negative values
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
2020-12-09 16:04 ` [Bug c++/98216] " redi at gcc dot gnu.org
@ 2020-12-10 7:33 ` rguenth at gcc dot gnu.org
2020-12-10 17:05 ` redi at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-12-10 7:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I guess the issue has to be with you using 'static constexpr auto arr' and
that not being correctly templated on the expression.
Well, confirmed your observation.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] std::array<double, N> template parameter error with negative values
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
2020-12-09 16:04 ` [Bug c++/98216] " redi at gcc dot gnu.org
2020-12-10 7:33 ` rguenth at gcc dot gnu.org
@ 2020-12-10 17:05 ` redi at gcc dot gnu.org
2020-12-10 17:16 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-10 17:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:
template<typename T, int N>
struct array
{
constexpr T& operator[](int n) { return d[n]; }
constexpr const T& operator[](int n) const { return d[n]; }
constexpr bool operator==(const array& a) const
{
for (int i = 0; i < N; ++i)
if (d[i] != a.d[i])
return false;
return true;
}
T d[N];
};
using an_array = array <double, 1>;
constexpr auto
add_array (an_array a, an_array const& b)
{
a[0] += b[0];
return a;
}
template <an_array A>
struct wrapper
{
static constexpr auto
arr = A;
};
template <an_array A1 , an_array A2>
auto
add (wrapper <A1> const&, wrapper <A2> const&)
{
return wrapper <add_array (A1, A2)> {};
}
constexpr auto ONE = an_array {{ 1. }};
constexpr auto MINUS_ONE = an_array {{ -1. }};
constexpr auto MINUS_TWO = an_array {{ -2. }};
int
main ()
{
auto a = wrapper <MINUS_TWO> {};
auto b = wrapper <ONE> {};
auto c = add (a, b);
__builtin_printf("%f %f %f\n", a.arr[0], b.arr[0], c.arr[0]);
if (c.arr != MINUS_ONE)
__builtin_abort();
}
Prints:
-2.000000 1.000000 -2.000000
Aborted (core dumped)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] std::array<double, N> template parameter error with negative values
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (2 preceding siblings ...)
2020-12-10 17:05 ` redi at gcc dot gnu.org
@ 2020-12-10 17:16 ` redi at gcc dot gnu.org
2020-12-10 17:56 ` emmanuel.le-trong@cnrs-orleans.fr
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-10 17:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:
struct an_array
{
constexpr bool operator==(const an_array& a) const { return d == a.d; }
double d;
};
constexpr auto
add_array (an_array a, an_array b)
{
a.d += b.d;
return a;
}
template <an_array A>
struct wrapper
{
static constexpr auto arr = A;
};
constexpr auto ONE = an_array {{ 1. }};
constexpr auto MINUS_ONE = an_array {{ -1. }};
constexpr auto MINUS_TWO = an_array {{ -2. }};
int
main ()
{
#ifndef FIX
auto a = wrapper <MINUS_TWO> {};
__builtin_printf("%f\n", a.arr.d);
#endif
auto c = wrapper <add_array (MINUS_TWO, ONE)> {};
__builtin_printf("%f\n", c.arr.d);
if (c.arr != MINUS_ONE)
__builtin_abort();
}
Prints:
-2.000000
-2.000000
Aborted (core dumped)
If you define FIX (i.e. don't instantiate wrapper<MINUS_TWO> first) it works:
-1.000000
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] std::array<double, N> template parameter error with negative values
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (3 preceding siblings ...)
2020-12-10 17:16 ` redi at gcc dot gnu.org
@ 2020-12-10 17:56 ` emmanuel.le-trong@cnrs-orleans.fr
2020-12-14 20:56 ` ppalka at gcc dot gnu.org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: emmanuel.le-trong@cnrs-orleans.fr @ 2020-12-10 17:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
--- Comment #4 from Emmanuel Le Trong <emmanuel.le-trong@cnrs-orleans.fr> ---
Looking at the symbols in your snippet:
$ nm -C toto | grep wrapper
0000000000402030 u wrapper<an_array{(double)[ffffffff00000000]}>::arr
That looks like a weird NaN to me.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] std::array<double, N> template parameter error with negative values
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (4 preceding siblings ...)
2020-12-10 17:56 ` emmanuel.le-trong@cnrs-orleans.fr
@ 2020-12-14 20:56 ` ppalka at gcc dot gnu.org
2021-07-27 8:08 ` [Bug c++/98216] [C++20] template mangling for double template argument is wrong pinskia at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-12-14 20:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Related testcase which may or may not be caused by the same underlying bug:
$ cat testcase.C
template <double s> void foo() {}
template void foo<-1.0>();
template void foo<-2.0>();
$ g++ -std=c++20 testcase.C
testcase.C:3:26: error: Two symbols with same comdat_group are not linked by
the same_comdat_group list.
3 | template void foo<-2.0>();
| ^
_Z3fooILdffffffff00000000EEvv/1 (void foo() [with double s = -2.0e+0])
@0x7fdb12c4aee0
Type: function definition analyzed
Visibility: force_output forced_by_abi no_reorder public weak
comdat_group:_Z3fooILdffffffff00000000EEvv one_only
previous sharing asm name: 0
References:
Referring:
Function flags: body
Called by:
Calls:
_Z3fooILdffffffff00000000EEvv/0 (void foo() [with double s = -1.0e+0])
@0x7fdb12c4add0
Type: function definition analyzed
Visibility: force_output forced_by_abi no_reorder public weak
comdat_group:_Z3fooILdffffffff00000000EEvv one_only
next sharing asm name: 1
References:
Referring:
Function flags: body
Called by:
Calls:
testcase.C:3:26: internal compiler error: symtab_node::verify failed
0xbebe81 symtab_node::verify_symtab_nodes()
/home/patrick/code/gcc/gcc/symtab.c:1406
0xc00586 symtab_node::checking_verify_symtab_nodes()
/home/patrick/code/gcc/gcc/cgraph.h:675
0xc00586 symbol_table::compile()
/home/patrick/code/gcc/gcc/cgraphunit.c:2277
0xc02f67 symbol_table::compile()
/home/patrick/code/gcc/gcc/cgraphunit.c:2274
0xc02f67 symbol_table::finalize_compilation_unit()
/home/patrick/code/gcc/gcc/cgraphunit.c:2542
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (5 preceding siblings ...)
2020-12-14 20:56 ` ppalka at gcc dot gnu.org
@ 2021-07-27 8:08 ` pinskia at gcc dot gnu.org
2021-09-23 18:57 ` ppalka at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 8:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bobmiller at nvidia dot com
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 100279 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (6 preceding siblings ...)
2021-07-27 8:08 ` [Bug c++/98216] [C++20] template mangling for double template argument is wrong pinskia at gcc dot gnu.org
@ 2021-09-23 18:57 ` ppalka at gcc dot gnu.org
2021-09-23 19:01 ` ppalka at gcc dot gnu.org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-23 18:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (7 preceding siblings ...)
2021-09-23 18:57 ` ppalka at gcc dot gnu.org
@ 2021-09-23 19:01 ` ppalka at gcc dot gnu.org
2021-09-24 16:36 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-23 19:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrei.popa105 at yahoo dot com
--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 102092 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (8 preceding siblings ...)
2021-09-23 19:01 ` ppalka at gcc dot gnu.org
@ 2021-09-24 16:36 ` cvs-commit at gcc dot gnu.org
2021-09-24 19:36 ` emmanuel.le-trong@cnrs-orleans.fr
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-24 16:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:34947d4e97ee72b26491cfe5ff4fa8258fadbe95
commit r12-3882-g34947d4e97ee72b26491cfe5ff4fa8258fadbe95
Author: Patrick Palka <ppalka@redhat.com>
Date: Fri Sep 24 12:36:26 2021 -0400
real: fix encoding of negative IEEE double/quad values [PR98216]
In encode_ieee_double/quad, the assignment
unsigned long WORD = r->sign << 31;
is intended to set the 31st bit of WORD whenever the sign bit is set.
But on LP64 hosts it also unintentionally sets the upper 32 bits of WORD,
because r->sign gets promoted from unsigned:1 to int and then the result
of the shift (equal to INT_MIN) gets sign extended from int to long.
In the C++ frontend, this bug causes incorrect mangling of negative
floating point values because the output of real_to_target called from
write_real_cst unexpectedly has the upper 32 bits of this word set,
which the caller doesn't mask out.
This patch fixes this by avoiding the unwanted sign extension. Note
that r0-53976 fixed the same bug in encode_ieee_single long ago.
PR c++/98216
PR c++/91292
gcc/ChangeLog:
* real.c (encode_ieee_double): Avoid unwanted sign extension.
(encode_ieee_quad): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/nontype-float2.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (9 preceding siblings ...)
2021-09-24 16:36 ` cvs-commit at gcc dot gnu.org
@ 2021-09-24 19:36 ` emmanuel.le-trong@cnrs-orleans.fr
2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: emmanuel.le-trong@cnrs-orleans.fr @ 2021-09-24 19:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
Emmanuel Le Trong <emmanuel.le-trong@cnrs-orleans.fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #9 from Emmanuel Le Trong <emmanuel.le-trong@cnrs-orleans.fr> ---
Fixed, thank you.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (10 preceding siblings ...)
2021-09-24 19:36 ` emmanuel.le-trong@cnrs-orleans.fr
@ 2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
2021-10-14 19:06 ` hq.ks at web dot de
2021-10-14 21:39 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-06 14:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:1682576e62d41cd761472943372b83aee514254a
commit r11-9083-g1682576e62d41cd761472943372b83aee514254a
Author: Patrick Palka <ppalka@redhat.com>
Date: Fri Sep 24 12:36:26 2021 -0400
real: fix encoding of negative IEEE double/quad values [PR98216]
In encode_ieee_double/quad, the assignment
unsigned long WORD = r->sign << 31;
is intended to set the 31st bit of WORD whenever the sign bit is set.
But on LP64 hosts it also unintentionally sets the upper 32 bits of WORD,
because r->sign gets promoted from unsigned:1 to int and then the result
of the shift (equal to INT_MIN) gets sign extended from int to long.
In the C++ frontend, this bug causes incorrect mangling of negative
floating point values because the output of real_to_target called from
write_real_cst unexpectedly has the upper 32 bits of this word set,
which the caller doesn't mask out.
This patch fixes this by avoiding the unwanted sign extension. Note
that r0-53976 fixed the same bug in encode_ieee_single long ago.
PR c++/98216
PR c++/91292
gcc/ChangeLog:
* real.c (encode_ieee_double): Avoid unwanted sign extension.
(encode_ieee_quad): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/nontype-float2.C: New test.
(cherry picked from commit 34947d4e97ee72b26491cfe5ff4fa8258fadbe95)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (11 preceding siblings ...)
2021-10-06 14:15 ` cvs-commit at gcc dot gnu.org
@ 2021-10-14 19:06 ` hq.ks at web dot de
2021-10-14 21:39 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: hq.ks at web dot de @ 2021-10-14 19:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
hq.ks at web dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hq.ks at web dot de
--- Comment #11 from hq.ks at web dot de ---
*** Bug 102754 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/98216] [C++20] template mangling for double template argument is wrong
2020-12-09 15:43 [Bug c++/98216] New: [C++20] std::array<double, N> template parameter error with negative values emmanuel.le-trong@cnrs-orleans.fr
` (12 preceding siblings ...)
2021-10-14 19:06 ` hq.ks at web dot de
@ 2021-10-14 21:39 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-14 21:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.3
^ permalink raw reply [flat|nested] 15+ messages in thread