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

            Bug ID: 95492
           Summary: Avoid recursive inlining for -O2
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.bolvansky at gmail dot com
  Target Milestone: ---

Test case from PR90949:

int puts(const char*);
void free(void*);
void* malloc(unsigned long);
#define NULL 0

struct Node
{
    struct Node* child;
};

void walk(struct Node* module, int cleanup)
{
    if (module == NULL) {
        return;
    }
    if (!cleanup) {
        puts("No cleanup");
    }
    walk(module->child, cleanup);
    if (cleanup) {
        free(module);
    }
}

int main()
{
    struct Node* node = malloc(sizeof(struct Node));
    node->child = NULL;
    walk(node, 1);
}

https://godbolt.org/z/aqVApt


Since GCC 10, GCC inlines recursion with -O2/-O3. With -O3, new bigger code is
justified, but for -O2, it is quite questionable whether GCC should inline it
or not (or possibly, less agressive "inlining" for -O2)

Reply via email to