mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
IRGen: honour -static-libclosure in block creation
When creating a block, ensure that we correctly associate the DLL Storage on the `_NSConcreteStackBlock` root object declaration based upon whether we are generating code with `-static-libclosure` being passed to the clang importer or not.
This commit is contained in:
@@ -78,8 +78,10 @@
|
||||
#include "swift/AST/SubstitutionMap.h"
|
||||
#include "swift/AST/Types.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
#include "swift/ClangImporter/ClangImporter.h"
|
||||
#include "swift/IRGen/Linking.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/Basic/CodeGenOptions.h"
|
||||
#include "clang/CodeGen/CodeGenABITypes.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
@@ -2755,6 +2757,9 @@ void irgen::emitBlockHeader(IRGenFunction &IGF,
|
||||
auto NSConcreteStackBlock =
|
||||
IGF.IGM.getModule()->getOrInsertGlobal("_NSConcreteStackBlock",
|
||||
IGF.IGM.ObjCClassStructTy);
|
||||
swift::ClangImporter *CI =
|
||||
static_cast<ClangImporter *>(IGF.IGM.Context.getClangModuleLoader());
|
||||
if (!CI->getCodeGenOpts().StaticClosure)
|
||||
ApplyIRLinkage(IRLinkage::ExternalImport)
|
||||
.to(cast<llvm::GlobalVariable>(NSConcreteStackBlock));
|
||||
|
||||
|
||||
@@ -1170,10 +1170,15 @@ llvm::Constant *swift::getRuntimeFn(
|
||||
|
||||
if (IGM && useDllStorage(IGM->Triple) && IsExternal) {
|
||||
bool bIsImported = true;
|
||||
swift::ASTContext &Context = IGM->Context;
|
||||
if (IGM->getSwiftModule()->getPublicModuleName(true).str() == ModuleName)
|
||||
bIsImported = false;
|
||||
else if (ModuleDecl *MD = IGM->Context.getModuleByName(ModuleName))
|
||||
else if (ModuleDecl *MD = Context.getModuleByName(ModuleName))
|
||||
bIsImported = !MD->isStaticLibrary();
|
||||
else if (strcmp(ModuleName, "BlocksRuntime") == 0)
|
||||
bIsImported =
|
||||
!static_cast<ClangImporter *>(Context.getClangModuleLoader())
|
||||
->getCodeGenOpts().StaticClosure;
|
||||
|
||||
if (bIsImported)
|
||||
fn->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
|
||||
|
||||
9
test/IRGen/static-libclosure.swift
Normal file
9
test/IRGen/static-libclosure.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
// RUN: %swift_frontend_plain -target x86_64-unknown-windows-msvc -primary-file %s -parse-as-library -parse-stdlib -nostdimport -module-name M -emit-ir -Xcc -static-libclosure -o - | %FileCheck %s
|
||||
|
||||
public let block: @convention(block) () -> () = {
|
||||
}
|
||||
|
||||
// CHECK-NOT: @_NSConcreteStackBlock = external dllimport global
|
||||
// CHECK-NOT: declare dllimport ptr @_Block_copy(ptr)
|
||||
// CHECK: @_NSConcreteStackBlock = external global
|
||||
// CHECK: declare ptr @_Block_copy(ptr)
|
||||
Reference in New Issue
Block a user