ClangImporter: don't import clang SPI attributes by default

This commit is contained in:
Xi Ge
2021-09-28 10:46:08 -07:00
parent d301f66f54
commit a4b4b1fa65
8 changed files with 27 additions and 13 deletions

View File

@@ -740,6 +740,9 @@ namespace swift {
/// When set, don't look for or load overlays. /// When set, don't look for or load overlays.
bool DisableOverlayModules = false; bool DisableOverlayModules = false;
/// When set, import SPI_AVAILABLE symbols with Swift SPI attribtues.
bool EnableClangSPI = false;
/// When set, don't enforce warnings with -Werror. /// When set, don't enforce warnings with -Werror.
bool DebuggerSupport = false; bool DebuggerSupport = false;
@@ -767,7 +770,8 @@ namespace swift {
DetailedPreprocessingRecord, DetailedPreprocessingRecord,
ImportForwardDeclarations, ImportForwardDeclarations,
DisableSwiftBridgeAttr, DisableSwiftBridgeAttr,
DisableOverlayModules); DisableOverlayModules,
EnableClangSPI);
} }
}; };

View File

@@ -138,6 +138,10 @@ def disable_testable_attr_requires_testable_module :
Flag<["-"], "disable-testable-attr-requires-testable-module">, Flag<["-"], "disable-testable-attr-requires-testable-module">,
HelpText<"Disable checking of @testable">; HelpText<"Disable checking of @testable">;
def enable_clang_spi :
Flag<["-"], "enable-clang-spi">,
HelpText<"Import Clang SPIs as Swift SPIs">;
def enable_target_os_checking : def enable_target_os_checking :
Flag<["-"], "enable-target-os-checking">, Flag<["-"], "enable-target-os-checking">,
HelpText<"Enable checking the target OS of serialized modules">; HelpText<"Enable checking the target OS of serialized modules">;

View File

@@ -2197,6 +2197,7 @@ ClangImporter::Implementation::Implementation(
DisableSwiftBridgeAttr(ctx.ClangImporterOpts.DisableSwiftBridgeAttr), DisableSwiftBridgeAttr(ctx.ClangImporterOpts.DisableSwiftBridgeAttr),
BridgingHeaderExplicitlyRequested(!ctx.ClangImporterOpts.BridgingHeader.empty()), BridgingHeaderExplicitlyRequested(!ctx.ClangImporterOpts.BridgingHeader.empty()),
DisableOverlayModules(ctx.ClangImporterOpts.DisableOverlayModules), DisableOverlayModules(ctx.ClangImporterOpts.DisableOverlayModules),
EnableClangSPI(ctx.ClangImporterOpts.EnableClangSPI),
IsReadingBridgingPCH(false), IsReadingBridgingPCH(false),
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)), CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
BridgingHeaderLookupTable(new SwiftLookupTable(nullptr)), BridgingHeaderLookupTable(new SwiftLookupTable(nullptr)),

View File

@@ -8711,15 +8711,17 @@ void ClangImporter::Implementation::importAttributes(
AnyUnavailable = true; AnyUnavailable = true;
} }
if (isUsingMacroName(getClangASTContext().getSourceManager(), if (EnableClangSPI) {
avail->getLoc(), "SPI_AVAILABLE") || if (isUsingMacroName(getClangASTContext().getSourceManager(),
isUsingMacroName(getClangASTContext().getSourceManager(), avail->getLoc(), "SPI_AVAILABLE") ||
avail->getLoc(), "__SPI_AVAILABLE")) { isUsingMacroName(getClangASTContext().getSourceManager(),
// The decl has been marked as SPI in the header by using the SPI macro, avail->getLoc(), "__SPI_AVAILABLE")) {
// thus we add the SPI attribute to it with a default group name. // The decl has been marked as SPI in the header by using the SPI macro,
MappedDecl->getAttrs().add(SPIAccessControlAttr::create(SwiftContext, // thus we add the SPI attribute to it with a default group name.
SourceLoc(), SourceRange(), MappedDecl->getAttrs().add(SPIAccessControlAttr::create(SwiftContext,
SwiftContext.getIdentifier(CLANG_MODULE_DEFUALT_SPI_GROUP_NAME))); SourceLoc(), SourceRange(),
SwiftContext.getIdentifier(CLANG_MODULE_DEFUALT_SPI_GROUP_NAME)));
}
} }
StringRef message = avail->getMessage(); StringRef message = avail->getMessage();

View File

@@ -337,6 +337,7 @@ public:
const bool DisableSwiftBridgeAttr; const bool DisableSwiftBridgeAttr;
const bool BridgingHeaderExplicitlyRequested; const bool BridgingHeaderExplicitlyRequested;
const bool DisableOverlayModules; const bool DisableOverlayModules;
const bool EnableClangSPI;
bool IsReadingBridgingPCH; bool IsReadingBridgingPCH;
llvm::SmallVector<clang::serialization::SubmoduleID, 2> PCHImportedSubmodules; llvm::SmallVector<clang::serialization::SubmoduleID, 2> PCHImportedSubmodules;

View File

@@ -1052,6 +1052,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
Opts.DisableOverlayModules |= Args.hasArg(OPT_emit_imported_modules); Opts.DisableOverlayModules |= Args.hasArg(OPT_emit_imported_modules);
Opts.EnableClangSPI |= Args.hasArg(OPT_enable_clang_spi);
Opts.ExtraArgsOnly |= Args.hasArg(OPT_extra_clang_options_only); Opts.ExtraArgsOnly |= Args.hasArg(OPT_extra_clang_options_only);
if (const Arg *A = Args.getLastArg(OPT_pch_output_dir)) { if (const Arg *A = Args.getLastArg(OPT_pch_output_dir)) {

View File

@@ -1,6 +1,6 @@
// REQUIRES: OS=macosx // REQUIRES: OS=macosx
// RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -verify -DNOT_UNDERLYING // RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -enable-clang-spi -verify -DNOT_UNDERLYING
// RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -module-name SPIContainer -import-underlying-module -verify // RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -module-name SPIContainer -import-underlying-module -enable-clang-spi -verify
#if NOT_UNDERLYING #if NOT_UNDERLYING
import SPIContainer import SPIContainer

View File

@@ -1,5 +1,5 @@
// REQUIRES: OS=macosx // REQUIRES: OS=macosx
// RUN: %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/frameworks/SPIContainer.framework/Headers/SPIContainer.h -verify // RUN: %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/frameworks/SPIContainer.framework/Headers/SPIContainer.h -enable-clang-spi -verify
@_spi(a) public let a: SPIInterface1 @_spi(a) public let a: SPIInterface1