Skip to content

Commit 04f09d6

Browse files
[Modules] Soft reset diagnostics when clang module import failed
Swift compiler can try to import clang modules which might fail to load. In this case, the clang diagnostic engine is reset to ignore the errors, but the hard reset also clears out the states, including the diagnostics options and current states. This will affect the future clang module imports and diagnostics. Use a soft reset that only clears the errors but not the other states. rdar://139723218
1 parent ecf7ac9 commit 04f09d6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/ClangImporter/ClangDiagnosticConsumer.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@ class ClangDiagnosticConsumer : public clang::TextDiagnosticPrinter {
5353
~LoadModuleRAII() {
5454
if (Consumer) {
5555
// We must reset Clang's diagnostic engine here since we know that only
56-
// the module lookup errors have been emitted. While the ClangDiagnosticConsumer
57-
// takes care of filtering out the diagnostics from the output and from
58-
// being handled by Swift's DiagnosticEngine, we must ensure to also
59-
// reset Clang's DiagnosticEngine because its state is queried in later
60-
// stages of compilation and errors emitted on "module_not_found" should not
61-
// be counted.
62-
// FIXME: We must instead allow for module loading in Clang to fail without
63-
// needing to emit a diagnostic.
64-
if (Engine && Consumer->CurrentImportNotFound && DiagEngineClearPriorToLookup)
65-
Engine->Reset();
56+
// the module lookup errors have been emitted. While the
57+
// ClangDiagnosticConsumer takes care of filtering out the diagnostics
58+
// from the output and from being handled by Swift's DiagnosticEngine,
59+
// we must ensure to also reset Clang's DiagnosticEngine because its
60+
// state is queried in later stages of compilation and errors emitted on
61+
// "module_not_found" should not be counted. Use a soft reset that only
62+
// clear the errors but not reset the states.
63+
// FIXME: We must instead allow for module loading in Clang to fail
64+
// without needing to emit a diagnostic.
65+
if (Engine && Consumer->CurrentImportNotFound &&
66+
DiagEngineClearPriorToLookup)
67+
Engine->Reset(/*soft=*/true);
6668
Consumer->CurrentImport = nullptr;
6769
Consumer->CurrentImportNotFound = false;
6870
}

0 commit comments

Comments
 (0)