[clang] Don't emit type tests for dllexport/import classes

According to https://clang.llvm.org/docs/LTOVisibility.html, classes on
Windows with dllimport/export receive public LTO visibility and
therefore should not participate in WPD.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D129700
This commit is contained in:
Arthur Eubanks 2022-07-13 15:51:15 -07:00
parent 9cf1881f8f
commit f34ecb50e2
2 changed files with 7 additions and 10 deletions

View File

@ -1212,7 +1212,8 @@ void CodeGenModule::EmitDeferredVTables() {
}
bool CodeGenModule::AlwaysHasLTOVisibilityPublic(const CXXRecordDecl *RD) {
if (RD->hasAttr<LTOVisibilityPublicAttr>() || RD->hasAttr<UuidAttr>())
if (RD->hasAttr<LTOVisibilityPublicAttr>() || RD->hasAttr<UuidAttr>() ||
RD->hasAttr<DLLExportAttr>() || RD->hasAttr<DLLImportAttr>())
return true;
if (!getCodeGenOpts().LTOVisibilityPublicStd)
@ -1239,13 +1240,9 @@ bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
if (!isExternallyVisible(LV.getLinkage()))
return true;
if (getTriple().isOSBinFormatCOFF()) {
if (RD->hasAttr<DLLExportAttr>() || RD->hasAttr<DLLImportAttr>())
return false;
} else {
if (LV.getVisibility() != HiddenVisibility)
return false;
}
if (!getTriple().isOSBinFormatCOFF() &&
LV.getVisibility() != HiddenVisibility)
return false;
return !AlwaysHasLTOVisibilityPublic(RD);
}

View File

@ -74,10 +74,10 @@ void f(C1 *c1, C2 *c2, C3 *c3, C4 *c4, C5 *c5, C6 *c6, std::C7 *c7,
// MS: type.test{{.*}}!"?AUC2@@"
c2->f();
// ITANIUM: type.test{{.*}}!"_ZTS2C3"
// MS: type.test{{.*}}!"?AUC3@@"
// MS-NOT: type.test{{.*}}!"?AUC3@@"
c3->f();
// ITANIUM: type.test{{.*}}!"_ZTS2C4"
// MS: type.test{{.*}}!"?AUC4@@"
// MS-NOT: type.test{{.*}}!"?AUC4@@"
c4->f();
// ITANIUM-NOT: type.test{{.*}}!"_ZTS2C5"
// MS-NOT: type.test{{.*}}!"?AUC5@@"