Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang not devirtualizing final methods based on anonymous namespace info #16983

Open Quuxplusone opened 11 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR16984
Status NEW
Importance P normal
Reported by Chris Lattner (clattner@nondot.org)
Reported on 2013-08-23 13:57:30 -0700
Last modified on 2015-07-16 14:46:57 -0700
Version unspecified
Hardware PC All
CC benny.kra@gmail.com, dgregor@apple.com, geek4civic@gmail.com, hfinkel@anl.gov, llvm-bugs@lists.llvm.org, nlewycky@google.com, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Consider:

class C1 {
  virtual void bar();
  virtual void baz();
};

namespace {
class C2 : public C1 {
  void bar() { baz(); }
  void baz() {}
};
}

C1 *test() { return new C2(); }

Clang currently doesn't devirtualize the call from bar() to baz() in C2...
unless you mark C2 with the C++11 "final" attribute.  The compiler should be
able to infer "finalness" of the class in this case.  This matters for
codebases like LLVM's that are C++'98 and use anonymous namespaces a lot.
Quuxplusone commented 11 years ago

http://llvm-reviews.chandlerc.com/D1511