Skip to content

Commit 5a387d7

Browse files
authored
Merge pull request #37548 from bnbarham/5.5-cherry-rdar78039608
[5.5][Frontend] Do not output swiftinterface when there has been errors
2 parents 11ece0f + 63ce918 commit 5a387d7

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ static void emitIndexData(const CompilerInstance &Instance) {
815815
/// anything past type-checking.
816816
static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
817817
CompilerInstance &Instance) {
818+
const auto &Context = Instance.getASTContext();
818819
const auto &Invocation = Instance.getInvocation();
819820
const FrontendOptions &opts = Invocation.getFrontendOptions();
820821

@@ -833,7 +834,8 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
833834
// failure does not mean skipping the rest.
834835
bool hadAnyError = false;
835836

836-
if (opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
837+
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
838+
opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
837839
std::string BridgingHeaderPathForPrint;
838840
if (!opts.ImplicitObjCHeaderPath.empty()) {
839841
if (opts.BridgingHeaderDirForPrint.hasValue()) {
@@ -853,6 +855,11 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
853855
Invocation.isModuleExternallyConsumed(Instance.getMainModule()));
854856
}
855857

858+
// Only want the header if there's been any errors, ie. there's not much
859+
// point outputting a swiftinterface for an invalid module
860+
if (Context.hadError())
861+
return hadAnyError;
862+
856863
if (opts.InputsAndOutputs.hasModuleInterfaceOutputPath()) {
857864
hadAnyError |= printModuleInterfaceIfNeeded(
858865
Invocation.getModuleInterfaceOutputPathForWholeModule(),
@@ -995,9 +1002,10 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
9951002

9961003
dumpAPIIfNeeded(Instance);
9971004
}
998-
if (!ctx.hadError() || opts.AllowModuleWithCompilerErrors) {
999-
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
1000-
}
1005+
1006+
// Contains the hadError checks internally, we still want to output the
1007+
// Objective-C header when there's errors and currently allowing them
1008+
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
10011009

10021010
// Verify reference dependencies of the current compilation job. Note this
10031011
// must be run *before* verifying diagnostics so that the former can be tested

test/Frontend/allow-errors.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/mods)
3+
// RUN: touch %t/empty.swift
24

35
// The module should be generated regardless of errors, including .swiftdeps, .d,
46
// .swiftsourceinfo, etc. Diagnostics should still be output as well
57

6-
// RUN: %target-swift-frontend -verify -emit-module -o %t/errors.swiftmodule -emit-module-source-info -emit-module-doc -emit-reference-dependencies-path %t/errors.swiftdeps -emit-dependencies-path %t/errors.d -experimental-allow-module-with-compiler-errors -primary-file %s
7-
// RUN: llvm-bcanalyzer %t/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
8-
// RUN: ls %t/errors.swiftdeps %t/errors.d %t/errors.swiftsourceinfo %t/errors.swiftdoc
8+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsmain.partial.swiftmodule -emit-reference-dependencies-path %t/mods/errorsmain.partial.swiftdeps -experimental-allow-module-with-compiler-errors -primary-file %s
9+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errorsempty.partial.swiftmodule %t/empty.swift
10+
// RUN: %target-swift-frontend -module-name errors -emit-module -o %t/mods/errors.swiftmodule -experimental-allow-module-with-compiler-errors %t/mods/errorsmain.partial.swiftmodule %t/mods/errorsempty.partial.swiftmodule -emit-module-source-info -emit-module-doc -emit-dependencies-path %t/mods/errors.d -emit-objc-header -emit-objc-header-path %t/mods/errors.h -emit-module-interface-path %t/mods/errors.swiftinterface -emit-tbd-path %t/mods/errors.tbd
11+
12+
// RUN: llvm-bcanalyzer %t/mods/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
13+
// RUN: ls %t/mods/errorsmain.partial.swiftdeps %t/mods/errors.d %t/mods/errors.swiftsourceinfo %t/mods/errors.swiftdoc %t/mods/errors.h
14+
// RUN: not ls %t/mods/errors.swiftinterface
15+
// RUN: not ls %t/mods/errors.tbd
916
// CHECK-BC-NOT: UnknownCode
1017

1118
public func invalid() -> undefined {} // expected-error {{cannot find type 'undefined'}}

0 commit comments

Comments
 (0)