public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept
@ 2024-02-26 13:46 yves.bailly at hexagon dot com
  2024-02-26 16:58 ` [Bug c++/114114] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: yves.bailly at hexagon dot com @ 2024-02-26 13:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114114
           Summary: Internal compiler error on function-local conditional
                    noexcept
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yves.bailly at hexagon dot com
  Target Milestone: ---

Created attachment 57542
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57542&action=edit
Preprocessed file from -save-temps

Tested on:
- Ubuntu 22.04 with distribution's GCC 11.4.0
- Ubuntu 22.04 with "home-build" GCC 13.2.0
- Ubuntu 23.10 with distribution's GCC 13.2.0
- Godbolt's compiler explorer with GCC x86-64 "trunk"

The following code causes an internal compiler error on (1):

--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
#include <iostream>

enum class YesNo: bool { Yes, No };
template <typename E>
[[nodiscard]] constexpr bool isYes(const E e) noexcept {
   return e == E::Yes;
}

template<YesNo yes_or_no>
constexpr void test() {
    [[maybe_unused]] constexpr bool is_yes = isYes(yes_or_no); // (1)

    struct S
    {
#if true // (2)
        constexpr S() noexcept(is_yes)
        { std::cout << "boo\n"; }

        // The following compiles fine:
#else
        constexpr S() noexcept(yes_or_no == YesNo::Yes)
        { std::cout << "boo ok\n"; }
#endif
    };

    S s;
}

int main()
{
    test<YesNo::Yes>();
}

--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---

Changing the "true" to "false" on (2) makes the code compile, link and run
fine.

Note: this code is accepted by Clang and MSVC.


Output of gcc -v:
Using built-in specs.
COLLECT_GCC=/home/ybailly/gcc13/bin/g++
COLLECT_LTO_WRAPPER=/home/ybailly/gcc13/libexec/gcc/x86_64-pc-linux-gnu/13.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-13.2.0/configure --prefix=/home/ybailly/gcc13
--enable-languages=c,c++,fortran --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (GCC) 


Output of "~/gcc13/bin/g++ -o test_gcc.x -std=c++20 test_gcc.cpp":
test_gcc.cpp: In instantiation of ‘constexpr test()::S::S() [with YesNo
yes_or_no = YesNo::Yes]’:
test_gcc.cpp:16:19:   required from ‘constexpr test()::S::S() [with YesNo
yes_or_no = YesNo::Yes]’
test_gcc.cpp:24:5:   required from ‘constexpr void test() [with YesNo yes_or_no
= YesNo::Yes]’
test_gcc.cpp:31:21:   required from here
test_gcc.cpp:11:37: internal compiler error: Segmentation fault
   11 |     [[maybe_unused]] constexpr bool is_yes = isYes(yes_or_no); // (1)
      |                                     ^~~~~~
0xe013bf crash_signal
        ../../gcc-13.2.0/gcc/toplev.cc:314
0x7f673d7e851f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x88089e hash_table<hash_map<tree_node*, tree_node*,
simple_hashmap_traits<default_hash_traits<tree_node*>, tree_node*>
>::hash_entry, false, xcallocator>::find_slot_with_hash(tree_node* const&,
unsigned int, insert_option)
        ../../gcc-13.2.0/gcc/hash-table.h:1039
0x88089e hash_map<tree_node*, tree_node*,
simple_hashmap_traits<default_hash_traits<tree_node*>, tree_node*>
>::put(tree_node* const&, tree_node* const&)
        ../../gcc-13.2.0/gcc/hash-map.h:170
0x88089e register_local_specialization(tree_node*, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:1970
0x896009 tsubst_decl
        ../../gcc-13.2.0/gcc/cp/pt.cc:15446
0x885904 tsubst_copy
        ../../gcc-13.2.0/gcc/cp/pt.cc:17417
0x886588 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:21676
0x889bed maybe_instantiate_noexcept(tree_node*, int)
        ../../gcc-13.2.0/gcc/cp/pt.cc:26754
0x88ddb2 regenerate_decl_from_template
        ../../gcc-13.2.0/gcc/cp/pt.cc:26553
0x88ddb2 instantiate_body
        ../../gcc-13.2.0/gcc/cp/pt.cc:26865
0x88e678 instantiate_decl(tree_node*, bool, bool)
        ../../gcc-13.2.0/gcc/cp/pt.cc:27217
0x897f22 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:19397
0x898431 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:18844
0x898431 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:18858
0x898265 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:18844
0x898265 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:19238
0x88de06 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-13.2.0/gcc/cp/pt.cc:26930
0x88de06 instantiate_body
        ../../gcc-13.2.0/gcc/cp/pt.cc:26930
0x88e678 instantiate_decl(tree_node*, bool, bool)
        ../../gcc-13.2.0/gcc/cp/pt.cc:27217


Preprocessed file attached, greatly reduced by removing <iostream> - the same
error appears without it.

Regards,

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

* [Bug c++/114114] [11/12/13/14 Regression] Internal compiler error on function-local conditional noexcept
  2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
@ 2024-02-26 16:58 ` pinskia at gcc dot gnu.org
  2024-02-26 17:01 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-26 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.5
            Summary|Internal compiler error on  |[11/12/13/14 Regression]
                   |function-local conditional  |Internal compiler error on
                   |noexcept                    |function-local conditional
                   |                            |noexcept
      Known to fail|                            |10.1.0, 9.3.0, 9.5.0
      Known to work|                            |9.1.0, 9.2.0

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

* [Bug c++/114114] [11/12/13/14 Regression] Internal compiler error on function-local conditional noexcept
  2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
  2024-02-26 16:58 ` [Bug c++/114114] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-02-26 17:01 ` pinskia at gcc dot gnu.org
  2024-02-26 19:01 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-26 17:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-02-26
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, reduced further:
```
template<bool yes_or_no>
constexpr void test() {
    constexpr bool is_yes = yes_or_no;
    struct S
    {
        constexpr S() noexcept(is_yes){}
    };
    S s;
}
int main()
{
    test<true>();
}
```

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

* [Bug c++/114114] [11/12/13/14 Regression] Internal compiler error on function-local conditional noexcept
  2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
  2024-02-26 16:58 ` [Bug c++/114114] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
  2024-02-26 17:01 ` pinskia at gcc dot gnu.org
@ 2024-02-26 19:01 ` ppalka at gcc dot gnu.org
  2024-02-27  8:24 ` yves.bailly at hexagon dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-02-26 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=91378
                 CC|                            |ppalka at gcc dot gnu.org
           Keywords|needs-bisection             |

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r10-2274-gd40e36310722e6

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

* [Bug c++/114114] [11/12/13/14 Regression] Internal compiler error on function-local conditional noexcept
  2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
                   ` (2 preceding siblings ...)
  2024-02-26 19:01 ` ppalka at gcc dot gnu.org
@ 2024-02-27  8:24 ` yves.bailly at hexagon dot com
  2024-03-04 18:21 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: yves.bailly at hexagon dot com @ 2024-02-27  8:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Yves Bailly <yves.bailly at hexagon dot com> ---
Due credits to Stefano Bellotti <stefano.bellotti@hexagon.com> for writing the
code that triggers the ICE - I only did the paperwork.

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

* [Bug c++/114114] [11/12/13/14 Regression] Internal compiler error on function-local conditional noexcept
  2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
                   ` (3 preceding siblings ...)
  2024-02-27  8:24 ` yves.bailly at hexagon dot com
@ 2024-03-04 18:21 ` mpolacek at gcc dot gnu.org
  2024-03-06 16:47 ` cvs-commit at gcc dot gnu.org
  2024-03-06 16:48 ` [Bug c++/114114] [11/12/13 " mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-03-04 18:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
                 CC|                            |mpolacek at gcc dot gnu.org

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

* [Bug c++/114114] [11/12/13/14 Regression] Internal compiler error on function-local conditional noexcept
  2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
                   ` (4 preceding siblings ...)
  2024-03-04 18:21 ` mpolacek at gcc dot gnu.org
@ 2024-03-06 16:47 ` cvs-commit at gcc dot gnu.org
  2024-03-06 16:48 ` [Bug c++/114114] [11/12/13 " mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-06 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:dc6c3bfb59baab28b998e18396c06087b6d9b0ed

commit r14-9339-gdc6c3bfb59baab28b998e18396c06087b6d9b0ed
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Mar 5 13:33:10 2024 -0500

    c++: ICE with noexcept and local specialization [PR114114]

    Here we ICE because we call register_local_specialization while
    local_specializations is null, so

      local_specializations->put ();

    crashes on null this.  It's null since maybe_instantiate_noexcept calls
    push_to_top_level which creates a new scope.  Normally, I would have
    guessed that we need a new local_specialization_stack.  But here we're
    dealing with an operand of a noexcept, which is an unevaluated operand,
    and those aren't registered in the hash map.  maybe_instantiate_noexcept
    wasn't signalling that it's substituting an unevaluated operand though.

            PR c++/114114

    gcc/cp/ChangeLog:

            * pt.cc (maybe_instantiate_noexcept): Save/restore
            cp_unevaluated_operand, c_inhibit_evaluation_warnings, and
            cp_noexcept_operand around the tsubst_expr call.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/noexcept84.C: New test.

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

* [Bug c++/114114] [11/12/13 Regression] Internal compiler error on function-local conditional noexcept
  2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
                   ` (5 preceding siblings ...)
  2024-03-06 16:47 ` cvs-commit at gcc dot gnu.org
@ 2024-03-06 16:48 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-03-06 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13/14 Regression]    |[11/12/13 Regression]
                   |Internal compiler error on  |Internal compiler error on
                   |function-local conditional  |function-local conditional
                   |noexcept                    |noexcept

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.

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

end of thread, other threads:[~2024-03-06 16:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26 13:46 [Bug c++/114114] New: Internal compiler error on function-local conditional noexcept yves.bailly at hexagon dot com
2024-02-26 16:58 ` [Bug c++/114114] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-02-26 17:01 ` pinskia at gcc dot gnu.org
2024-02-26 19:01 ` ppalka at gcc dot gnu.org
2024-02-27  8:24 ` yves.bailly at hexagon dot com
2024-03-04 18:21 ` mpolacek at gcc dot gnu.org
2024-03-06 16:47 ` cvs-commit at gcc dot gnu.org
2024-03-06 16:48 ` [Bug c++/114114] [11/12/13 " mpolacek 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).