From 4b7b59812822d535372818c20b4ee6007ae15bd9 Mon Sep 17 00:00:00 2001 From: fushijian Date: Tue, 27 Jun 2023 20:27:39 +0800 Subject: [PATCH] should inherit -strict-implicit-module-context when build sub swiftinterface --- lib/Frontend/ModuleInterfaceLoader.cpp | 10 ++++++++++ .../ImportsMacroSpecificClangModule.swiftinterface | 2 +- ...ubImportsMacroSpecificClangModule.swiftinterface | 4 ++++ .../clang-args-transitive-availability.swift | 13 +++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/ModuleInterface/Inputs/macro-only-module/SubImportsMacroSpecificClangModule.swiftinterface diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 7d4e311dc5a7a..9212827023007 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -1669,6 +1669,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl( // Configure front-end input. auto &SubFEOpts = genericSubInvocation.getFrontendOptions(); SubFEOpts.RequestedAction = LoaderOpts.requestedAction; + SubFEOpts.StrictImplicitModuleContext = + LoaderOpts.strictImplicitModuleContext; if (!moduleCachePath.empty()) { genericSubInvocation.setClangModuleCachePath(moduleCachePath); } @@ -1866,6 +1868,10 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName, // invocation. CompilerInvocation subInvocation = genericSubInvocation; + // save `StrictImplicitModuleContext` + bool StrictImplicitModuleContext = + subInvocation.getFrontendOptions().StrictImplicitModuleContext; + // Save the target triple from the original context. llvm::Triple originalTargetTriple(subInvocation.getLangOptions().Target); @@ -1950,6 +1956,10 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName, BuildArgs.push_back(parsedTargetTriple.str()); } + // restore `StrictImplicitModuleContext` + subInvocation.getFrontendOptions().StrictImplicitModuleContext = + StrictImplicitModuleContext; + CompilerInstance subInstance; SubCompilerInstanceInfo info; info.Instance = &subInstance; diff --git a/test/ModuleInterface/Inputs/macro-only-module/ImportsMacroSpecificClangModule.swiftinterface b/test/ModuleInterface/Inputs/macro-only-module/ImportsMacroSpecificClangModule.swiftinterface index ae845e320a1b8..a993222d0de00 100644 --- a/test/ModuleInterface/Inputs/macro-only-module/ImportsMacroSpecificClangModule.swiftinterface +++ b/test/ModuleInterface/Inputs/macro-only-module/ImportsMacroSpecificClangModule.swiftinterface @@ -1,4 +1,4 @@ // swift-interface-format-version: 1.0 // swift-module-flags: -enable-library-evolution -module-name ImportsMacroSpecificClangModule -import OnlyWithMacro +import SubImportsMacroSpecificClangModule diff --git a/test/ModuleInterface/Inputs/macro-only-module/SubImportsMacroSpecificClangModule.swiftinterface b/test/ModuleInterface/Inputs/macro-only-module/SubImportsMacroSpecificClangModule.swiftinterface new file mode 100644 index 0000000000000..6f39ed30d1538 --- /dev/null +++ b/test/ModuleInterface/Inputs/macro-only-module/SubImportsMacroSpecificClangModule.swiftinterface @@ -0,0 +1,4 @@ +// swift-interface-format-version: 1.0 +// swift-module-flags: -enable-library-evolution -module-name SubImportsMacroSpecificClangModule + +import OnlyWithMacro \ No newline at end of file diff --git a/test/ModuleInterface/clang-args-transitive-availability.swift b/test/ModuleInterface/clang-args-transitive-availability.swift index 0c79ed4996da1..e34ec43b7337d 100644 --- a/test/ModuleInterface/clang-args-transitive-availability.swift +++ b/test/ModuleInterface/clang-args-transitive-availability.swift @@ -30,6 +30,19 @@ import ImportsMacroSpecificClangModule //CHECK-NEXT: ], //CHECK-NEXT: "directDependencies": [ //CHECK-NEXT: { +//CHECK-NEXT: "swift": "SubImportsMacroSpecificClangModule" +//CHECK-NEXT: }, +//CHECK-NEXT: { +//CHECK-NEXT: "swift": "SwiftOnoneSupport" + +//CHECK: "swift": "SubImportsMacroSpecificClangModule" +//CHECK-NEXT: }, +//CHECK-NEXT: { +//CHECK-NEXT: "modulePath": "{{.*}}{{/|\\}}SubImportsMacroSpecificClangModule-{{.*}}.swiftmodule", +//CHECK-NEXT: "sourceFiles": [ +//CHECK-NEXT: ], +//CHECK-NEXT: "directDependencies": [ +//CHECK-NEXT: { //CHECK-NEXT: "clang": "OnlyWithMacro" // CHECK: "clang": "OnlyWithMacro"