Skip to content

Commit 2dfdbf2

Browse files
author
David Ungar
authored
Merge pull request #19261 from davidungar/rdar-43438753-and-43033749-fix-batch-mode-no-diags-swift-4.2-branch
[Batch Mode] Very simple and safe fix for batch mode diagnostic suppression bug. Includes tests.
2 parents be88499 + a4316b1 commit 2dfdbf2

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

include/swift/AST/DiagnosticConsumer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
187187
ConsumerSpecificInfoForSubsequentNotes = None;
188188

189189
bool HasAnErrorBeenConsumed = false;
190+
bool HasAnErrorWithNoConsumerSpecificInfoBeenConsumed = false;
190191

191192
public:
192193
/// Takes ownership of the DiagnosticConsumers specified in \p consumers.

lib/AST/DiagnosticConsumer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ void FileSpecificDiagnosticConsumer::handleDiagnostic(
172172
break;
173173
}
174174
if (!consumerSpecificInfo.hasValue()) {
175+
HasAnErrorWithNoConsumerSpecificInfoBeenConsumed |=
176+
Kind == DiagnosticKind::Error;
175177
for (auto &subConsumer : SubConsumers) {
176178
if (subConsumer.second) {
177179
subConsumer.second->handleDiagnostic(SM, Loc, Kind, FormatString,
@@ -205,6 +207,11 @@ void FileSpecificDiagnosticConsumer::
205207
tellSubconsumersToInformDriverOfIncompleteBatchModeCompilation() const {
206208
if (!HasAnErrorBeenConsumed)
207209
return;
210+
if (HasAnErrorWithNoConsumerSpecificInfoBeenConsumed) {
211+
// An error was emitted, but not through a consumerSpecificInfo.
212+
// Falling through would lose the error, so return.
213+
return;
214+
}
208215
for (auto &info : ConsumersOrderedByRange) {
209216
if (!info.hasAnErrorBeenEmitted && info.consumer)
210217
info.consumer->informDriverOfIncompleteBatchModeCompilation();

test/ClangImporter/diags_from_header.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
// RUN: not %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/diags_from_header.h 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-WARN
1+
// RUN: not %target-swift-frontend -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/diags_from_header.h -serialize-diagnostics-path %t.dia 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-WARN
2+
// RUN: test -s %t.dia
3+
// RUN: c-index-test -read-diagnostics %t.dia 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-WARN
4+
5+
// Also check batch mode (multiple primary files).
6+
// RUN: not %target-swift-frontend -typecheck -primary-file %s -primary-file %S/../Inputs/empty.swift -enable-objc-interop -import-objc-header %S/Inputs/diags_from_header.h -serialize-diagnostics-path %t.1.dia -serialize-diagnostics-path %t.2.dia 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-WARN
7+
// RUN: test -s %t.1.dia
8+
// RUN: c-index-test -read-diagnostics %t.1.dia 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-WARN
9+
// RUN: test -s %t.2.dia
10+
// RUN: c-index-test -read-diagnostics %t.2.dia 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-WARN
211

3-
// RUN: not %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/diags_from_header.h -Xcc -Wno-#warnings 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-NO-WARN
12+
// Verify that -Wno-* options are applied.
13+
// RUN: not %target-swift-frontend -typecheck %s -enable-objc-interop -import-objc-header %S/Inputs/diags_from_header.h -Xcc -Wno-#warnings 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-NO-WARN
414

515
// CHECK-WARN: diags_from_header.h:{{.*}}:2: warning: "here is some warning about something"
616
// CHECK-NO-WARN-NOT: warning about something

test/ClangImporter/diags_from_module.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
// RUN: not %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -Xcc -D -Xcc FOO 2> %t.err.txt
2-
// RUN: %FileCheck -input-file=%t.err.txt %s
1+
// RUN: %empty-directory(%t)
2+
// RUN: not %target-swift-frontend -module-cache-path %t -enable-objc-interop -typecheck %s -F %S/Inputs/frameworks -serialize-diagnostics-path %t.dia -Xcc -D -Xcc FOO 2>&1 | %FileCheck %s
3+
// RUN: test -s %t.dia
4+
// RUN: c-index-test -read-diagnostics %t.dia 2>&1 | %FileCheck %s
5+
6+
// RUN: %empty-directory(%t)
7+
// RUN: %target-swift-frontend -module-cache-path %t -enable-objc-interop -typecheck %s -F %S/Inputs/frameworks -serialize-diagnostics-path %t.warn.dia 2>&1 | %FileCheck %s -check-prefix CHECK-WARN
8+
// RUN: test -s %t.warn.dia
9+
// RUN: c-index-test -read-diagnostics %t.warn.dia 2>&1 | %FileCheck %s -check-prefix CHECK-WARN
10+
11+
// Also check batch mode (multiple primary files).
12+
// RUN: %empty-directory(%t)
13+
// RUN: not %target-swift-frontend -module-cache-path %t -enable-objc-interop -typecheck -primary-file %s -primary-file %S/../Inputs/empty.swift -F %S/Inputs/frameworks -serialize-diagnostics-path %t.1.dia -serialize-diagnostics-path %t.2.dia -Xcc -D -Xcc FOO 2>&1 | %FileCheck %s
14+
// RUN: test -s %t.1.dia
15+
// RUN: c-index-test -read-diagnostics %t.1.dia 2>&1 | %FileCheck %s
16+
// RUN: c-index-test -read-diagnostics %t.1.dia 2>&1 | %FileCheck %s -check-prefix CHECK-PRIMARY
17+
// RUN: test -s %t.2.dia
18+
// RUN: c-index-test -read-diagnostics %t.2.dia 2>&1 | %FileCheck %s
319

4-
// RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks 2> %t.warn.txt
5-
// RUN: %FileCheck -input-file=%t.warn.txt %s -check-prefix=CHECK-WARN
20+
// RUN: %empty-directory(%t)
21+
// RUN: %target-swift-frontend -module-cache-path %t -enable-objc-interop -typecheck -primary-file %s -primary-file %S/../Inputs/empty.swift -F %S/Inputs/frameworks -serialize-diagnostics-path %t.warn.1.dia -serialize-diagnostics-path %t.warn.2.dia 2>&1 | %FileCheck %s -check-prefix CHECK-WARN
22+
// RUN: test -s %t.1.dia
23+
// RUN: c-index-test -read-diagnostics %t.warn.1.dia 2>&1 | %FileCheck %s -check-prefix=CHECK-WARN
24+
// RUN: test -s %t.2.dia
25+
// RUN: c-index-test -read-diagnostics %t.warn.2.dia 2>&1 | %FileCheck %s -check-prefix=CHECK-WARN
626

7-
// RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -Xcc -Wno-#warnings 2> %t.nowarn.txt
8-
// RUN: %FileCheck -input-file=%t.nowarn.txt %s -check-prefix=CHECK-NO-WARN -allow-empty
27+
// Verify that -Wno-* options are applied.
28+
// RUN: %empty-directory(%t)
929

10-
// XFAIL: linux
30+
// RUN: %target-swift-frontend -module-cache-path %t -enable-objc-interop -typecheck %s -F %S/Inputs/frameworks -Xcc -Wno-#warnings 2>&1 | %FileCheck -check-prefix CHECK-NO-WARN -allow-empty %s
1131

1232
import Module
1333

1434
// CHECK: Another.h:2:4: error: Module should have been built without -DFOO
1535
// CHECK: Sub2.h:2:9: error: could not build module 'Another'
16-
// CHECK: diags_from_module.swift:[[@LINE-4]]:8: error: could not build Objective-C module 'Module'
36+
// CHECK-PRIMARY: diags_from_module.swift:[[@LINE-4]]:8: error: could not build Objective-C module 'Module'
1737

1838
// CHECK-WARN: Sub2.h:7:2: warning: here is some warning about something
1939
// FIXME: show the clang warning: <module-includes>:1:1: warning: umbrella header for module 'Module' does not include header 'NotInModule.h' [-Wincomplete-umbrella]

0 commit comments

Comments
 (0)