<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr">Theoretically, there is no requirement that a symbol for Rectangle::colour be provided by the object file with the key function. In practice I'd expect the symbol would probably be provided anyway, but I think this would formally be a new ABI requirement.</div><div dir="ltr"><br></div><div dir="ltr">There might also be symbol visibility issues (eg with -fvisibility-inlines-hidden).</div><div dir="ltr"><br></div><div dir="ltr">On Mon, 28 May 2018, 10:48 David Blaikie via cfe-dev, <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Nothing immediately jumps out at me as making this invalid... (but I have a nagging feeling that there probably is an issue and I'm likely missing it - I imagine Richard Smith (CC'd), John McCall, etc, would be more likely to spot the nuances here)<div><br><div class="gmail_quote"><div dir="ltr">On Mon, May 28, 2018 at 7:47 AM Hans Wennborg via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a>> wrote:<br></div><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>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>