public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only
@ 2023-09-08 20:56 gyrovorbis at gmail dot com
  2023-09-08 21:13 ` [Bug target/111343] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gyrovorbis at gmail dot com @ 2023-09-08 20:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111343
           Summary: [SH] Including <cmath> in C++23 causes an ICE with
                    -m4-single-only
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gyrovorbis at gmail dot com
  Target Milestone: ---

We recently updated from GCC12 to GCC13 in the Sega Dreamcast indie SDK,
KallistiOS, and while pretty much everything has worked fantastically, we are
encountering a pretty serious ICE when attempting to include the <cmath> header
with the -m4-single-only SH-specific flag (which treats doubles as floats),
when compiling as C++23.

The minimal program to reproduce the issue is here:

#include <cmath>

int main(int argc, char* argv[]) { 
    return 0;
}

We are building with: -std=c++23 -m4-single-only


Note that without the -m4-single-only flag, the ICE disappears. Note also that
without including <cmath>, with this flag, the following static assertion
fails:

static_assert(sizeof(__STDCPP_FLOAT64_T__) == 8,
             "Oh god, Dreamcast broke!");


Here is a link to a repro in Compiler Explorer: https://godbolt.org/z/MrE8a47oq

I'm assuming the addition of the new C++23 <stdfloat> types is clashing with
the `-m4-single-only` flag, as it doesn't seem as though when these types are
created, there is any checking for sizeof(double) or anything target-specific:
https://github.com/gcc-mirror/gcc/blob/a7d052b3200c7928d903a0242b8cfd75d131e374/gcc/c-family/c-cppbuiltin.cc#L1265

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

* [Bug target/111343] [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only
  2023-09-08 20:56 [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only gyrovorbis at gmail dot com
@ 2023-09-08 21:13 ` pinskia at gcc dot gnu.org
  2023-09-27  5:02 ` olegendo at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-08 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely introduced by  r13-2887-gb04208895fed34171eac6 which implements
C++23 extended floating point types ...

And the use of _Float32 but now sizeof(double) == sizeof(float) ==
sizeof(_Float32)

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

* [Bug target/111343] [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only
  2023-09-08 20:56 [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only gyrovorbis at gmail dot com
  2023-09-08 21:13 ` [Bug target/111343] " pinskia at gcc dot gnu.org
@ 2023-09-27  5:02 ` olegendo at gcc dot gnu.org
  2024-06-17  8:48 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: olegendo at gcc dot gnu.org @ 2023-09-27  5:02 UTC (permalink / raw)
  To: gcc-bugs

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

Oleg Endo <olegendo at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|SH4                         |sh*-*-*
                 CC|                            |olegendo at gcc dot gnu.org

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> ---
I think this would be a problem on all targets where DF is forced to be SF,
which I think is not a good thing at all.  It's also causing problems with
Fortan.

I'm not sure if it makes sense to add support for DF == SF in the libraries.

Perhaps at least on SH4 the -m4-single-only option shouldn't be used generally
to build whole projects, but rather only a few files where it's really needed.

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

* [Bug target/111343] [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only
  2023-09-08 20:56 [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only gyrovorbis at gmail dot com
  2023-09-08 21:13 ` [Bug target/111343] " pinskia at gcc dot gnu.org
  2023-09-27  5:02 ` olegendo at gcc dot gnu.org
@ 2024-06-17  8:48 ` jakub at gcc dot gnu.org
  2024-06-17 16:59 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-06-17  8:48 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Untested fix below.  I wasn't aware any targets would actually have float the
same as double.  C++23 says here:
http://eel.is/c++draft/conv.rank#2.2 that double has higher rank than float
http://eel.is/c++draft/conv.rank#2.5 and that extended type with same set of
values as 2+ standard types has same rank as double.  As I've only thought
about the double same as long double case, I've only handled that case there.
No testcase for testsuite, as this needs to be tested in avr/sh specific
g++.target only and needs proper options/effective target macros to find out if
that is really the float same as double configuration.  Will defer testcases to
the respective target maintainers.

2024-06-17  Jakub Jelinek  <jakub@redhat.com>

        PR target/111343
        PR c++/115511
        * typeck.cc (cp_compare_floating_point_conversion_ranks): If an
        extended floating point type mv1 has same set of values as more
        than one standard floating point type and mv2 is float, return 2.

--- gcc/cp/typeck.cc.jj 2024-06-04 13:19:03.755604346 +0200
+++ gcc/cp/typeck.cc    2024-06-17 10:32:02.063088961 +0200
@@ -393,6 +393,9 @@ cp_compare_floating_point_conversion_ran
      has higher rank.  */
   if (cnt > 1 && mv2 == long_double_type_node)
     return -2;
+  /* And similarly if t2 is float, t2 has lower rank.  */
+  if (cnt > 1 && mv2 == float_type_node)
+    return 2;
   /* Otherwise, they have equal rank, but extended types
      (other than std::bfloat16_t) have higher subrank.
      std::bfloat16_t shouldn't have equal rank to any standard

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

* [Bug target/111343] [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only
  2023-09-08 20:56 [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only gyrovorbis at gmail dot com
                   ` (2 preceding siblings ...)
  2024-06-17  8:48 ` jakub at gcc dot gnu.org
@ 2024-06-17 16:59 ` cvs-commit at gcc dot gnu.org
  2024-06-17 17:19 ` cvs-commit at gcc dot gnu.org
  2024-06-17 17:23 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-17 16:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:8584c98f370cd91647c184ce58141508ca478a12

commit r15-1380-g8584c98f370cd91647c184ce58141508ca478a12
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jun 17 18:53:21 2024 +0200

    c++: Fix up floating point conversion rank comparison for _Float32 and
float if float/double are same size [PR115511]

    On AVR and SH with some options sizeof (float) == sizeof (double) and
    the 2 types have the same set of values.
    http://eel.is/c++draft/conv.rank#2.2 for this says that double still
    has bigger rank than float and http://eel.is/c++draft/conv.rank#2.2
    says that extended type with the same set of values as more than one
    standard floating point type shall have the same rank as double.
    I've implemented the latter rule as
       if (cnt > 1 && mv2 == long_double_type_node)
         return -2;
    with the _Float64/double/long double case having same mode case (various
    targets with -mlong-double-64) in mind.
    But never thought there are actually targets where float and double
    are the same, that needs handling too, if cnt > 1 (that is the extended
    type mv1 has same set of values as 2 or 3 of float/double/long double)
    and mv2 is float, we need to return 2, because mv1 in that case should
    have same rank as double and double has bigger rank than float.

    2024-06-17  Jakub Jelinek  <jakub@redhat.com>

            PR target/111343
            PR c++/115511
            * typeck.cc (cp_compare_floating_point_conversion_ranks): If an
            extended floating point type mv1 has same set of values as more
            than one standard floating point type and mv2 is float, return 2.

            * g++.dg/cpp23/ext-floating18.C: New test.

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

* [Bug target/111343] [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only
  2023-09-08 20:56 [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only gyrovorbis at gmail dot com
                   ` (3 preceding siblings ...)
  2024-06-17 16:59 ` cvs-commit at gcc dot gnu.org
@ 2024-06-17 17:19 ` cvs-commit at gcc dot gnu.org
  2024-06-17 17:23 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-17 17:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5be6d9d2a9854c05f3c019deb9fe95eca7248140

commit r14-10321-g5be6d9d2a9854c05f3c019deb9fe95eca7248140
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jun 17 18:53:21 2024 +0200

    c++: Fix up floating point conversion rank comparison for _Float32 and
float if float/double are same size [PR115511]

    On AVR and SH with some options sizeof (float) == sizeof (double) and
    the 2 types have the same set of values.
    http://eel.is/c++draft/conv.rank#2.2 for this says that double still
    has bigger rank than float and http://eel.is/c++draft/conv.rank#2.2
    says that extended type with the same set of values as more than one
    standard floating point type shall have the same rank as double.
    I've implemented the latter rule as
       if (cnt > 1 && mv2 == long_double_type_node)
         return -2;
    with the _Float64/double/long double case having same mode case (various
    targets with -mlong-double-64) in mind.
    But never thought there are actually targets where float and double
    are the same, that needs handling too, if cnt > 1 (that is the extended
    type mv1 has same set of values as 2 or 3 of float/double/long double)
    and mv2 is float, we need to return 2, because mv1 in that case should
    have same rank as double and double has bigger rank than float.

    2024-06-17  Jakub Jelinek  <jakub@redhat.com>

            PR target/111343
            PR c++/115511
            * typeck.cc (cp_compare_floating_point_conversion_ranks): If an
            extended floating point type mv1 has same set of values as more
            than one standard floating point type and mv2 is float, return 2.

            * g++.dg/cpp23/ext-floating18.C: New test.

    (cherry picked from commit 8584c98f370cd91647c184ce58141508ca478a12)

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

* [Bug target/111343] [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only
  2023-09-08 20:56 [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only gyrovorbis at gmail dot com
                   ` (4 preceding siblings ...)
  2024-06-17 17:19 ` cvs-commit at gcc dot gnu.org
@ 2024-06-17 17:23 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-17 17:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:6d0a0c547a6c8425d432129fc90869305fef7bc2

commit r13-8853-g6d0a0c547a6c8425d432129fc90869305fef7bc2
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jun 17 18:53:21 2024 +0200

    c++: Fix up floating point conversion rank comparison for _Float32 and
float if float/double are same size [PR115511]

    On AVR and SH with some options sizeof (float) == sizeof (double) and
    the 2 types have the same set of values.
    http://eel.is/c++draft/conv.rank#2.2 for this says that double still
    has bigger rank than float and http://eel.is/c++draft/conv.rank#2.2
    says that extended type with the same set of values as more than one
    standard floating point type shall have the same rank as double.
    I've implemented the latter rule as
       if (cnt > 1 && mv2 == long_double_type_node)
         return -2;
    with the _Float64/double/long double case having same mode case (various
    targets with -mlong-double-64) in mind.
    But never thought there are actually targets where float and double
    are the same, that needs handling too, if cnt > 1 (that is the extended
    type mv1 has same set of values as 2 or 3 of float/double/long double)
    and mv2 is float, we need to return 2, because mv1 in that case should
    have same rank as double and double has bigger rank than float.

    2024-06-17  Jakub Jelinek  <jakub@redhat.com>

            PR target/111343
            PR c++/115511
            * typeck.cc (cp_compare_floating_point_conversion_ranks): If an
            extended floating point type mv1 has same set of values as more
            than one standard floating point type and mv2 is float, return 2.

            * g++.dg/cpp23/ext-floating18.C: New test.

    (cherry picked from commit 8584c98f370cd91647c184ce58141508ca478a12)

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

end of thread, other threads:[~2024-06-17 17:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-08 20:56 [Bug c++/111343] New: [SH] Including <cmath> in C++23 causes an ICE with -m4-single-only gyrovorbis at gmail dot com
2023-09-08 21:13 ` [Bug target/111343] " pinskia at gcc dot gnu.org
2023-09-27  5:02 ` olegendo at gcc dot gnu.org
2024-06-17  8:48 ` jakub at gcc dot gnu.org
2024-06-17 16:59 ` cvs-commit at gcc dot gnu.org
2024-06-17 17:19 ` cvs-commit at gcc dot gnu.org
2024-06-17 17:23 ` cvs-commit 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).