[cfe-commits] More on templates and vtables

Rafael Espindola espindola at google.com
Mon Mar 22 19:39:41 PDT 2010


At a high level there are two things we have to decide about templates
and vtables
*) When do we *must* produce a vtable
*) When we don't have too, how much effort do we want to put to avoid it

On a IRC discussion we agreed that for

template<typename T>
class C {
  virtual ~C() { }
  void foo();
};
template<>
void C<char>::foo() {
}

we should produce a vtable, otherwise we would force the user to use
an explicit template instantiation definition (as gcc effectively
does).

Given the above decision it is interesting to consider what we should
do when the above example is followed by
extern template C<char>;

* Should we change our mind and not produce a vtable?
* If producing a vtable, should we also irgen the methods?

Currently we produce the vtable and *some* methods. The reason we
produce some is a bug in how we handle implicit methods.

On the first item, I think that we *should* emit the vtable, otherwise
things would get really complicated.  For example, we would have to
force vtable emission on explicit template instantiation declarations.

On the second item, we are already delaying the vtable emission
anyway, I think we should use the opportunity to avoid emitting
functions we don't need. The attached patch fixes that for implicit
methods.  The patch has 3 parts (other than the test)

* Propagate the fact that we have seen the extern template
(Sema::ActOnExplicitInstantiation)
* Don't get eager in the codegen when we see a
TSK_ExplicitInstantiationDeclaration (CGVtableInfo::MaybeEmitVtable).
* Correctly handle implicitly declare methods in GetLinkageForFunction.

The patch is clean on "make test". Is it OK if it also passes a bootstrap?

Cheers,
-- 
Rafael Ávila de Espíndola
-------------- next part --------------
A non-text attachment was scrubbed...
Name: destructor.patch
Type: text/x-patch
Size: 3946 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100322/09c12bd5/attachment.bin>


More information about the cfe-commits mailing list