Bug 113088 - [12/13 Regression] Segmentation fault with empty try/catch following try/catch with returns + noexcept destructor
Summary: [12/13 Regression] Segmentation fault with empty try/catch following try/catc...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.3.0
: P2 normal
Target Milestone: 12.4
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2023-12-19 23:40 UTC by Matt Beardsley
Modified: 2024-01-24 19:47 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.4.0, 14.0
Known to fail: 12.3.0, 13.2.0
Last reconfirmed: 2023-12-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Beardsley 2023-12-19 23:40:54 UTC
Compiling this works with gcc 11.4, but produces ICE (segv) with 12.1 (and onwards, including trunk according to compiler explorer)


g++ x.cpp

x.cpp contains the following:


struct X {
    ~X() {}
};

struct Y {
    ~Y() noexcept(false) {}
};

X foo() {
    try {
        return {};
    } catch (...) {
        Y{};
        return {};
    }

    try {
    } catch (...) {
    }
}


<source>: In function 'X foo()':
<source>:18:5: internal compiler error: Segmentation fault
   18 |     } catch (...) {
      |     ^
0x262852c internal_error(char const*, ...)
	???:0
0xb6109c maybe_splice_retval_cleanup(tree_node*, bool)
	???:0
0xcbd15f do_poplevel(tree_node*)
	???:0
0xcc068d finish_compound_stmt(tree_node*)
	???:0
0xc4a0ca c_parse_file()
	???:0
0xd9a469 c_common_parse_file()
	???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1


https://godbolt.org/z/b853srj6d
Comment 1 Patrick Palka 2023-12-20 00:29:26 UTC
Confirmed, started with r12-6333-gb10e031458d541.
Comment 2 GCC Commits 2023-12-20 17:31:37 UTC
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:02c0b49798228d777610f898cd9d63ebec43656d

commit r14-6754-g02c0b49798228d777610f898cd9d63ebec43656d
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 20 11:06:27 2023 -0500

    c++: throwing dtor and empty try [PR113088]
    
    maybe_splice_retval_cleanup assumed that the function body can't be empty if
    there's a throwing cleanup, but when I added cleanups to try blocks in
    r12-6333-gb10e031458d541 I didn't adjust that assumption.
    
            PR c++/113088
            PR c++/33799
    
    gcc/cp/ChangeLog:
    
            * except.cc (maybe_splice_retval_cleanup): Handle an empty block.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/eh/return2.C: New test.
Comment 3 GCC Commits 2024-01-24 19:39:01 UTC
The releases/gcc-13 branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:60bfd373a1891ae2349dc67313d104079ce8c706

commit r13-8247-g60bfd373a1891ae2349dc67313d104079ce8c706
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 20 11:06:27 2023 -0500

    c++: throwing dtor and empty try [PR113088]
    
    maybe_splice_retval_cleanup assumed that the function body can't be empty if
    there's a throwing cleanup, but when I added cleanups to try blocks in
    r12-6333-gb10e031458d541 I didn't adjust that assumption.
    
            PR c++/113088
            PR c++/33799
    
    gcc/cp/ChangeLog:
    
            * except.cc (maybe_splice_retval_cleanup): Handle an empty block.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/eh/return2.C: New test.
    
    (cherry picked from commit 02c0b49798228d777610f898cd9d63ebec43656d)
Comment 4 GCC Commits 2024-01-24 19:40:46 UTC
The releases/gcc-12 branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

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

commit r12-10110-gb0605cd4a12e9162cc56abc69ca1048947c72689
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Dec 20 11:06:27 2023 -0500

    c++: throwing dtor and empty try [PR113088]
    
    maybe_splice_retval_cleanup assumed that the function body can't be empty if
    there's a throwing cleanup, but when I added cleanups to try blocks in
    r12-6333-gb10e031458d541 I didn't adjust that assumption.
    
            PR c++/113088
            PR c++/33799
    
    gcc/cp/ChangeLog:
    
            * except.cc (maybe_splice_retval_cleanup): Handle an empty block.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/eh/return2.C: New test.
    
    (cherry picked from commit 02c0b49798228d777610f898cd9d63ebec43656d)
Comment 5 Jason Merrill 2024-01-24 19:47:28 UTC
Fixed for 12.4/13.3.