@@ -4046,38 +4046,41 @@ IRGenModule::getAddrOfLLVMVariable(LinkEntity entity,
40464046 auto var = createVariable (*this , link, definitionType,
40474047 entity.getAlignment (*this ), DbgTy);
40484048
4049- // @escaping () -> ()
4050- // NOTE: we explicitly desugar the `Void` type for the return as the test
4051- // suite makes assumptions that it can emit the value witness table without a
4052- // standard library for the target. `Context.getVoidType()` will attempt to
4053- // lookup the `Decl` before returning the canonical type. To workaround this
4054- // dependency, we simply desugar the `Void` return type to `()`.
4055- static CanType kAnyFunctionType =
4056- FunctionType::get ({}, Context.TheEmptyTupleType ,
4057- ASTExtInfo{})->getCanonicalType ();
4049+ auto isZeroParamFunctionType = [this ](Type t) -> bool {
4050+ if (auto *funcTy = t->getAs <FunctionType>()) {
4051+ return (funcTy->getParams ().size () == 0 &&
4052+ funcTy->getResult ()->isEqual (Context.TheEmptyTupleType ));
4053+ }
4054+
4055+ return false ;
4056+ };
40584057
40594058 // Adjust the linkage for the well-known VWTs that are strongly defined
40604059 // in the runtime.
40614060 //
4062- // We special case the "AnyFunctionType" here as this type is referened
4061+ // We special case the "AnyFunctionType" here as this type is referenced
40634062 // inside the standard library with the definition being in the runtime
40644063 // preventing the normal detection from identifying that this is module
40654064 // local.
40664065 //
40674066 // If we are statically linking the standard library, we need to internalise
40684067 // the symbols.
4069- if (getSwiftModule ()->isStdlibModule () ||
4070- (Context.getStdlibModule () &&
4071- Context.getStdlibModule ()->isStaticLibrary ()))
4072- if (entity.isTypeKind () &&
4073- (IsWellKnownBuiltinOrStructralType (entity.getType ()) ||
4074- entity.getType () == kAnyFunctionType ))
4075- if (auto *GV = dyn_cast<llvm::GlobalValue>(var))
4076- if (GV->hasDLLImportStorageClass ())
4077- ApplyIRLinkage ({llvm::GlobalValue::ExternalLinkage,
4078- llvm::GlobalValue::DefaultVisibility,
4079- llvm::GlobalValue::DefaultStorageClass})
4080- .to (GV);
4068+ if (auto *GV = dyn_cast<llvm::GlobalValue>(var)) {
4069+ if (GV->hasDLLImportStorageClass ()) {
4070+ if (getSwiftModule ()->isStdlibModule () ||
4071+ (Context.getStdlibModule () &&
4072+ Context.getStdlibModule ()->isStaticLibrary ())) {
4073+ if (entity.isTypeKind () &&
4074+ (isWellKnownBuiltinOrStructuralType (entity.getType ()) ||
4075+ isZeroParamFunctionType (entity.getType ()))) {
4076+ ApplyIRLinkage ({llvm::GlobalValue::ExternalLinkage,
4077+ llvm::GlobalValue::DefaultVisibility,
4078+ llvm::GlobalValue::DefaultStorageClass})
4079+ .to (GV);
4080+ }
4081+ }
4082+ }
4083+ }
40814084
40824085 // Install the concrete definition if we have one.
40834086 if (definition && definition.hasInit ()) {
0 commit comments