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

            Bug ID: 123459
           Summary: [16 Regression] speculative inlining doesn't play nice
                    with always_inline
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amonakov at gcc dot gnu.org
  Target Milestone: ---

struct handler_chain {
    struct handler_chain *next;
    void (*handler)(struct handler_chain *);
};

__attribute__((always_inline))
static inline
void noop_handler(struct handler_chain *h)
{
    h = h->next;
    if (h) {
        h->handler(h);
    }
}

void test(struct handler_chain *h)
{
    h->handler = noop_handler;
    noop_handler(h);
}

gcc-15 accepts this, gcc-16 -O2 rejects with

error: inlining failed in call to 'always_inline' 'noop_handler': recursive
inlining

but that is not a recursive call, h->next->handler can be anything, not just
noop_handler

I don't think attempting to speculatively inline an always_inline function
should result in a compilation error like here. Either the speculation should
not be attempted, or always_inline should be ignored in a speculative context.

In practice this appears to break build of openmpi-5.0.9 with gcc-16:
https://bugs.gentoo.org/show_bug.cgi?id=967873

Reply via email to