Skip to content

Frontend: Honor warning suppression when parsing arguments from swiftinterfaces #78653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,11 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
bool suppressRemarks,
RequireOSSAModules_t requireOSSAModules);
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
DiagnosticEngine &subInstanceDiags,
SwiftInterfaceInfo &interfaceInfo,
StringRef interfacePath,
SourceLoc diagnosticLoc);

public:
InterfaceSubContextDelegateImpl(
SourceManager &SM, DiagnosticEngine *Diags,
Expand Down
34 changes: 20 additions & 14 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}

Expand Down Expand Up @@ -2236,11 +2237,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);
}

Expand All @@ -2252,21 +2267,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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions test/ModuleInterface/suppress-warnings.swift
Original file line number Diff line number Diff line change
@@ -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