Skip to content

[clang] Question about devirtualizationΒ #116070

@vient

Description

@vient

Here is the test case

struct A {
    virtual int f() {
        return 1;
    }

    int call_f() {
        return f();
    }
};

struct C final: public A {
    int f() override {
        return 3;
    }
};

int test1(C& c) {
    return c.f();
}

int test2(C& c) {
    return c.call_f();
}

Both Clang and GCC devirtualize f call in test1 but not in test2 - why is that so? C is final, what is the scenario when call to C::call_f does not lead to C::f?
https://godbolt.org/z/6Kv38jeYo

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:optimizationsquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions