Skip to content

clang fails to inline recursive function while gcc succeeds #58113

@jrmuizel

Description

@jrmuizel
#include <stdlib.h>

struct Foo {
    Foo * next;
};

static void drop_in_place(Foo* f) {
    if (f->next) { drop_in_place(f->next); }
    free(f);
}

void free_foo(Foo *f) {
    while (f) {
        Foo * next = f->next;
        f->next = 0;
        drop_in_place(f);
        f = next;
    }
}

See https://godbolt.org/z/YT4soroz9

GCC is able to inline drop_in_place and avoids calling it recursively.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions