Skip to content

Commit 2504791

Browse files
authored
Merge pull request #78653 from tshortli/suppress-option-parsing-warnings-in-swiftinterfaces
Frontend: Honor warning suppression when parsing arguments from swiftinterfaces
2 parents 1932d07 + 3c5ae23 commit 2504791

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,11 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
654654
bool suppressRemarks,
655655
RequireOSSAModules_t requireOSSAModules);
656656
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
657+
DiagnosticEngine &subInstanceDiags,
657658
SwiftInterfaceInfo &interfaceInfo,
658659
StringRef interfacePath,
659660
SourceLoc diagnosticLoc);
661+
660662
public:
661663
InterfaceSubContextDelegateImpl(
662664
SourceManager &SM, DiagnosticEngine *Diags,

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,8 +1814,9 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
18141814
}
18151815

18161816
bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
1817-
CompilerInvocation &subInvocation, SwiftInterfaceInfo &interfaceInfo,
1818-
StringRef interfacePath, SourceLoc diagnosticLoc) {
1817+
CompilerInvocation &subInvocation, DiagnosticEngine &subInstanceDiags,
1818+
SwiftInterfaceInfo &interfaceInfo, StringRef interfacePath,
1819+
SourceLoc diagnosticLoc) {
18191820
if (readSwiftInterfaceVersionAndArgs(SM, *Diags, ArgSaver, interfaceInfo,
18201821
interfacePath, diagnosticLoc,
18211822
subInvocation.getLangOptions().Target))
@@ -1833,7 +1834,7 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
18331834
}
18341835

18351836
SmallString<32> ExpectedModuleName = subInvocation.getModuleName();
1836-
if (subInvocation.parseArgs(interfaceInfo.Arguments, *Diags)) {
1837+
if (subInvocation.parseArgs(interfaceInfo.Arguments, subInstanceDiags)) {
18371838
return true;
18381839
}
18391840

@@ -2238,11 +2239,25 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
22382239
subInvocation.getFrontendOptions().InputsAndOutputs
22392240
.setMainAndSupplementaryOutputs(outputFiles, ModuleOutputPaths);
22402241

2242+
CompilerInstance subInstance;
2243+
ForwardingDiagnosticConsumer FDC(*Diags);
2244+
NullDiagnosticConsumer noopConsumer;
2245+
if (!silenceErrors) {
2246+
subInstance.addDiagnosticConsumer(&FDC);
2247+
} else {
2248+
subInstance.addDiagnosticConsumer(&noopConsumer);
2249+
}
2250+
2251+
// Eagerly suppress warnings if necessary, before parsing arguments.
2252+
if (subInvocation.getDiagnosticOptions().SuppressWarnings)
2253+
subInstance.getDiags().setSuppressWarnings(true);
2254+
22412255
SwiftInterfaceInfo interfaceInfo;
22422256
// Extract compiler arguments from the interface file and use them to configure
22432257
// the compiler invocation.
2244-
if (extractSwiftInterfaceVersionAndArgs(subInvocation, interfaceInfo,
2245-
interfacePath, diagLoc)) {
2258+
if (extractSwiftInterfaceVersionAndArgs(subInvocation, subInstance.getDiags(),
2259+
interfaceInfo, interfacePath,
2260+
diagLoc)) {
22462261
return std::make_error_code(std::errc::not_supported);
22472262
}
22482263

@@ -2254,21 +2269,12 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
22542269
subInvocation.getFrontendOptions().StrictImplicitModuleContext =
22552270
StrictImplicitModuleContext;
22562271

2257-
CompilerInstance subInstance;
22582272
SubCompilerInstanceInfo info;
22592273
info.Instance = &subInstance;
22602274
info.CompilerVersion = interfaceInfo.CompilerVersion;
22612275

22622276
subInstance.getSourceMgr().setFileSystem(SM.getFileSystem());
22632277

2264-
ForwardingDiagnosticConsumer FDC(*Diags);
2265-
NullDiagnosticConsumer noopConsumer;
2266-
if (!silenceErrors) {
2267-
subInstance.addDiagnosticConsumer(&FDC);
2268-
} else {
2269-
subInstance.addDiagnosticConsumer(&noopConsumer);
2270-
}
2271-
22722278
std::string InstanceSetupError;
22732279
if (subInstance.setup(subInvocation, InstanceSetupError)) {
22742280
return std::make_error_code(std::errc::not_supported);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name SuppressWarnings -swift-version 6 -enable-upcoming-feature ConciseMagicFile
3+
4+
import Swift
5+
6+
@inlinable public func neverMutated() {
7+
var x = 1
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend -compile-module-from-interface %S/Inputs/suppress-warnings/SuppressWarnings.swiftinterface -o /dev/null -module-name SuppressWarnings 2>&1 | %FileCheck %s --allow-empty
2+
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/suppress-warnings/ 2>&1 | %FileCheck %s --allow-empty
3+
4+
// Warnings should not be emitted when compiling SuppressWarnings from its interface
5+
// CHECK-NOT: warning
6+
7+
import SuppressWarnings

0 commit comments

Comments
 (0)