Recommit [ABI] [C++20] [Modules] Don't generate vtable if the class is defined in...
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 19 Jun 2023 02:35:16 +0000 (10:35 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 19 Jun 2023 02:41:12 +0000 (10:41 +0800)
commit2d8044ee8b19f23e0a7fe5cd35876515d0d1d72e
tree5c92b608b57ff9c38285fd8d4bf6711676c7b0ba
parentb9a134aa629de23a1dcf4be32e946e4e308fc64d
Recommit [ABI] [C++20] [Modules] Don't generate vtable if the class is defined in other module unit

Close https://github.com/llvm/llvm-project/issues/61940.

The root cause is that clang will generate vtable as strong symbol now
even if the corresponding class is defined in other module units. After
I check the wording in Itanium ABI, I find this is not inconsistent.
Itanium ABI 5.2.3
(https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable) says:

> The virtual table for a class is emitted in the same object containing
> the definition of its key function, i.e. the first non-pure virtual
> function that is not inline at the point of class definition.

So the current behavior is incorrect. This patch tries to address this.
Also I think we need to do a similar change for MSVC ABI. But I don't
find the formal wording. So I don't address this in this patch.

Reviewed By: rjmccall, iains, dblaikie

Differential Revision: https://reviews.llvm.org/D150023
clang/lib/CodeGen/CGVTables.cpp
clang/test/CodeGenCXX/modules-vtable.cppm [new file with mode: 0644]