https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80726
Bug ID: 80726
Summary: Destructor not inlined anymore (regression)
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: cuzdav at gmail dot com
Target Milestone: ---
Inlining regression with noexcept(true) destructor that could possible throw,
but doesn't.
This code demonstrates that in main(), the destructor for Foo is no longer
inlined using g++ 7.1 -O3 (also with the 8.0 snapshot). On the 6.x series it
is inlined.
Source:
// ---------------------------------------
bool shouldThrow = false;
struct Foo {
~Foo() {
if (shouldThrow) throw "hmm";
}
};
int main() {
Foo f;
}// ---------------------------------------
As evidenced on godbolt.org, for g++7.1, main() has function call for
destructor
.LC0:
.string "hmm"
Foo::~Foo():
movzx eax, BYTE PTR shouldThrow[rip]
test al, al
jne .L7
rep ret
.L7:
mov edi, 8
sub rsp, 8
call __cxa_allocate_exception
xor edx, edx
mov QWORD PTR [rax], OFFSET FLAT:.LC0
mov esi, OFFSET FLAT:typeinfo for char const*
mov rdi, rax
call __cxa_throw
main:
sub rsp, 24
lea rdi, [rsp+15]
call Foo::~Foo()
xor eax, eax
add rsp, 24
ret
shouldThrow:
.zero 1
But with 6.3 the destructor is inlined:
.LC0:
.string "hmm"
main:
movzx eax, BYTE PTR shouldThrow[rip]
test al, al
jne .L7
xor eax, eax
ret
.L7:
mov edi, 8
sub rsp, 8
call __cxa_allocate_exception
xor edx, edx
mov QWORD PTR [rax], OFFSET FLAT:.LC0
mov esi, OFFSET FLAT:typeinfo for char const*
mov rdi, rax
call __cxa_throw
shouldThrow:
.zero 1