Skip to content

Commit 1d97c49

Browse files
committed
[IRGen][WMO] type descriptors generated for an imported Clang types are always known local declarations
This fixes a LNK4217 linker warning when building code on Windows
1 parent 96ee57b commit 1d97c49

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/swift/IRGen/Linking.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,9 @@ class LinkEntity {
15971597
getKind() == Kind::DispatchThunkAllocator ||
15981598
getKind() == Kind::DispatchThunkDerivative;
15991599
}
1600+
bool isNominalTypeDescriptor() const {
1601+
return getKind() == Kind::NominalTypeDescriptor;
1602+
}
16001603

16011604
/// Determine whether this entity will be weak-imported.
16021605
bool isWeakImported(ModuleDecl *module) const;

lib/IRGen/GenDecl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,22 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
24122412
isKnownLocal = MD == swiftModule || MD->isStaticLibrary();
24132413
}
24142414

2415+
if (!isKnownLocal && !isDefinition) {
2416+
if (auto *entityDC = entity.getDeclContextForEmission()) {
2417+
auto *entitySF = entityDC->getModuleScopeContext();
2418+
bool clangImportedEntity = isa<ClangModuleUnit>(entitySF);
2419+
// Nominal type descriptor for a type imported from a Clang module
2420+
// is always a local declaration as it's generated on demand. When WMO is off, it's emitted into
2421+
// the current file's object file. When WMO is on, it's emitted into
2422+
// one of the object files in the current module, and thus it's never
2423+
// imported from outside of the module.
2424+
if (clangImportedEntity &&
2425+
entity.isNominalTypeDescriptor()) {
2426+
isKnownLocal = true;
2427+
}
2428+
}
2429+
}
2430+
24152431
bool weakImported = entity.isWeakImported(swiftModule);
24162432
result.IRL = getIRLinkage(result.Name, linkInfo,
24172433
entity.getLinkage(isDefinition), isDefinition,

0 commit comments

Comments
 (0)