Merge pull request #78653 from tshortli/suppress-option-parsing-warnings-in-swiftinterfaces

Frontend: Honor warning suppression when parsing arguments from swiftinterfaces
This commit is contained in:
Allan Shortlidge
2025-01-15 09:45:40 -08:00
committed by GitHub
4 changed files with 37 additions and 14 deletions

View File

@@ -654,9 +654,11 @@ private:
bool suppressRemarks,
RequireOSSAModules_t requireOSSAModules);
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
DiagnosticEngine &subInstanceDiags,
SwiftInterfaceInfo &interfaceInfo,
StringRef interfacePath,
SourceLoc diagnosticLoc);
public:
InterfaceSubContextDelegateImpl(
SourceManager &SM, DiagnosticEngine *Diags,

View File

@@ -1814,8 +1814,9 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
}
bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
CompilerInvocation &subInvocation, SwiftInterfaceInfo &interfaceInfo,
StringRef interfacePath, SourceLoc diagnosticLoc) {
CompilerInvocation &subInvocation, DiagnosticEngine &subInstanceDiags,
SwiftInterfaceInfo &interfaceInfo, StringRef interfacePath,
SourceLoc diagnosticLoc) {
if (readSwiftInterfaceVersionAndArgs(SM, *Diags, ArgSaver, interfaceInfo,
interfacePath, diagnosticLoc,
subInvocation.getLangOptions().Target))
@@ -1833,7 +1834,7 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
}
SmallString<32> ExpectedModuleName = subInvocation.getModuleName();
if (subInvocation.parseArgs(interfaceInfo.Arguments, *Diags)) {
if (subInvocation.parseArgs(interfaceInfo.Arguments, subInstanceDiags)) {
return true;
}
@@ -2238,11 +2239,25 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
subInvocation.getFrontendOptions().InputsAndOutputs
.setMainAndSupplementaryOutputs(outputFiles, ModuleOutputPaths);
CompilerInstance subInstance;
ForwardingDiagnosticConsumer FDC(*Diags);
NullDiagnosticConsumer noopConsumer;
if (!silenceErrors) {
subInstance.addDiagnosticConsumer(&FDC);
} else {
subInstance.addDiagnosticConsumer(&noopConsumer);
}
// Eagerly suppress warnings if necessary, before parsing arguments.
if (subInvocation.getDiagnosticOptions().SuppressWarnings)
subInstance.getDiags().setSuppressWarnings(true);
SwiftInterfaceInfo interfaceInfo;
// Extract compiler arguments from the interface file and use them to configure
// the compiler invocation.
if (extractSwiftInterfaceVersionAndArgs(subInvocation, interfaceInfo,
interfacePath, diagLoc)) {
if (extractSwiftInterfaceVersionAndArgs(subInvocation, subInstance.getDiags(),
interfaceInfo, interfacePath,
diagLoc)) {
return std::make_error_code(std::errc::not_supported);
}
@@ -2254,21 +2269,12 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
subInvocation.getFrontendOptions().StrictImplicitModuleContext =
StrictImplicitModuleContext;
CompilerInstance subInstance;
SubCompilerInstanceInfo info;
info.Instance = &subInstance;
info.CompilerVersion = interfaceInfo.CompilerVersion;
subInstance.getSourceMgr().setFileSystem(SM.getFileSystem());
ForwardingDiagnosticConsumer FDC(*Diags);
NullDiagnosticConsumer noopConsumer;
if (!silenceErrors) {
subInstance.addDiagnosticConsumer(&FDC);
} else {
subInstance.addDiagnosticConsumer(&noopConsumer);
}
std::string InstanceSetupError;
if (subInstance.setup(subInvocation, InstanceSetupError)) {
return std::make_error_code(std::errc::not_supported);

View File

@@ -0,0 +1,8 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name SuppressWarnings -swift-version 6 -enable-upcoming-feature ConciseMagicFile
import Swift
@inlinable public func neverMutated() {
var x = 1
}

View File

@@ -0,0 +1,7 @@
// 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
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/suppress-warnings/ 2>&1 | %FileCheck %s --allow-empty
// Warnings should not be emitted when compiling SuppressWarnings from its interface
// CHECK-NOT: warning
import SuppressWarnings