Produce direct calls instead of alias to linkonce_odr functions

Rafael EspĂ­ndola rafael.espindola at
Tue Nov 5 00:33:03 PST 2013

>> What happens is that at the end of GetOrCreateLLVMFunction we check if
>> we have a decl defined in class and if so add it to
>> DeferredDeclsToEmit. The net result is that we end up running
>> replaceAllUsesWith twice when something in DeferredDeclsToEmit causes
>> a new use of the destructor/constructor.
>> Do you think this is OK? If not I can add a list of "DeclsToReplace"
>> to Codegen and process that after EmitDeferred.
> Ah, that makes sense.  Sounds fine, if a little bit silly.

You were right. The example I tried worked because there was a call to
GetOrCreateLLVMFunction before every try to emit the decl, so we would
recreate the declaration before trying to emit it in EmitDeferred.


struct Option {
  virtual ~Option() {}
template <class DataType> class opt : public Option {};
template class opt<int>;
bool handleOccurrence() {
  Option x;
  return true;

the template instantiation will not cause a declaration to be created
and we assert when trying to replace the value the second time.

The attached patch fixes this by doing all replacements after the
deferred decls have been emitted. With this approach it should then be
easy to also handle

class foo {
class bar : public foo {

i.e., when we know a function is equal to one we don't have a definition for.


More information about the cfe-commits mailing list