Skip to content

exclude_from_explicit_instantiation doesn't seem to exclude virtual methods, causing problems after 84216d1 #66909

@zmodem

Description

@zmodem

Consider:

C:\src\llvm-project>cat \src\temp\a.cc
template <typename>
struct Fruit {
  __attribute((exclude_from_explicit_instantiation)) Fruit() {}

  virtual void __attribute((exclude_from_explicit_instantiation)) draw() {}
};

extern template struct Fruit<int>;

int main() {
  Fruit<int> f;
  return 0;
}

C:\src\llvm-project>build\bin\clang-cl \src\temp\a.cc -fuse-ld=lld
lld-link: error: undefined symbol: public: virtual void __cdecl Fruit<int>::draw(void)
>>> referenced by c:\src\temp\a-6ec007.obj:(const Fruit<int>::`vftable')
clang-cl: error: linker command failed with exit code 1 (use -v to see invocation)

It seems that despite the exclude_from_explicit_instantiation attribute on Fruit<>::draw, the explicit instantiation decl prevents the definition from being emitted when referenced by the vtable. Instead the definition of Fruit<>::draw will only get emitted once there's an explicit instantiation definition.

However, after 84216d1 that stopped working across DLL boundaries, since the method will no longer be dllimport/export.

It seems the exclusion from explicit instantiation is not working completely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions