https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119491
Bug ID: 119491 Summary: missed tail call due to exceptions which is empty Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: missed-optimization, tail-call Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Blocks: 119376 Target Milestone: --- Take this C++ code: ``` struct TcFieldData { struct DefaultInit {}; TcFieldData() {} }; struct TcParseTableBase; void target_atomic(TcFieldData data); template <typename VarintType> static inline __attribute__((always_inline)) void ShiftMixParseVarint( int &res1) { } static inline __attribute__((always_inline)) void ParseVarint(int *value) { int res = 0; ShiftMixParseVarint<int>(res); } void f(); unsigned char fast_idx_mask; TcFieldData bits; inline __attribute__((always_inline)) void TagDispatch(TcFieldData) { if (fast_idx_mask) f(); [[clang::musttail]] return target_atomic(bits); } void MpUnknownEnumFallback(TcFieldData data) { int tmp; ParseVarint(&tmp); [[clang::musttail]] return TagDispatch(TcFieldData{}); } ``` The musttail should not fail but currently does since we end up with: ``` <bb 5> [count: 0]: <L5>: goto <bb 8>; [100.00%] ... <bb 7> [count: 0]: <L4>: <bb 8> [count: 0]: <L2>: resx 1 ``` Which should be optimized away. We do optimize it away but after tailc is run. Note this is reduced from PR 119376 . Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119376 [Bug 119376] [15 Regression] musttail does not get dropped after inlining?