[llvm-bugs] [Bug 43640] New: `final` does not cause devirtualization of nested calls

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 10 09:18:05 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43640

            Bug ID: 43640
           Summary: `final` does not cause devirtualization of nested
                    calls
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: antoshkka at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider the example:

struct A {
    virtual int f() { return 0; }
    virtual int g() { return f() + 40; } 
};

struct B2 final : A {
    int g() override;
};
int B2::g() { return A::g(); }


`B2` is final, so any call to the virtual functions of `A` end up with a call
to the same function in `B2`. So `B2::g()` should inline the `A::g()` and get
optimized to:

int B2::g() { return B2::f() + 40; }

Which is just 40, because `B2::f()` always returns 0.


Godbolt playground: https://godbolt.org/z/skqgH8

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191010/d86ba9c6/attachment.html>


More information about the llvm-bugs mailing list