<div dir="ltr">Sounds like a great idea to experiment with, maybe behind a flag.<div><br></div><div>I'll note that Windows doesn't have key functions and that it'd be nice to have something like this there too. <a href="https://bugs.llvm.org/show_bug.cgi?id=33628">https://bugs.llvm.org/show_bug.cgi?id=33628</a> has some discussions about this (maybe we just want a /Zc:keyFunctions thingy for clang-cl).</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 28, 2018 at 10:46 AM, Hans Wennborg via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was poking around some object files and noticed function definitions<br>
that seemed unnecessary. They were for inline functions not actually<br>
used in the file except by reference from a vtable.<br>
<br>
For example:<br>
<br>
  struct Rectangle {<br>
    virtual int colour() { return 1; }<br>
    virtual void draw();<br>
  };<br>
<br>
  struct Square : public Rectangle {<br>
    virtual void draw() override;<br>
  };<br>
<br>
  void Square::draw() {}<br>
<br>
Both Clang and GCC will emit a definition of Rectangle::colour() here<br>
because it's referenced by Square's vtable which we must define, and<br>
it's an inline function so we don't know if it's defined anywhere<br>
else.<br>
<br>
But, don't we actually know it's defined elsewhere? Since Rectangle<br>
has a key function, its vtable will be defined elsewhere. That vtable<br>
will reference Rectangle::colour(), so that too must have a definition<br>
elsewhere. Could we use this reasoning to omit the definition of<br>
colour() in the current TU, or at least mark it available_externally?<br>
<br>
I'm thinking exploiting this could allow the compiler to emit a bit<br>
less code. Or is there something I'm missing?<br>
<br>
Cheers,<br>
Hans<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>