Skip to content

Commit cc3fddb

Browse files
committed
[pch] Honour -fallow-pch-with-compiler-errors for overall compilation status
Previously we would emit a PCH with errors, but fail the overall compilation. If run using the driver, that would result in removing the just-produced PCH. Instead, we should have the compilation result match whether we were able to emit the PCH. Differential Revision: https://reviews.llvm.org/D77159 rdar://61110294
1 parent 9dcb16b commit cc3fddb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/Serialization/GeneratePCH.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
5757
}
5858
}
5959

60+
// Errors that do not prevent the PCH from being written should not cause the
61+
// overall compilation to fail either.
62+
if (AllowASTWithErrors)
63+
PP.getDiagnostics().getClient()->clear();
64+
6065
// Emit the PCH file to the Buffer.
6166
assert(SemaPtr && "No Sema?");
6267
Buffer->Signature =

clang/test/Index/pch-with-errors.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ void foo(void) {
4242

4343
// RUN: not c-index-test -write-pch %t.pch foobar.c 2>&1 | FileCheck -check-prefix=NONEXISTENT %s
4444
// NONEXISTENT: Unable to load translation unit
45+
46+
// RUN: %clang -x c-header %s -o %t-clang.h.pch -Xclang -detailed-preprocessing-record -Xclang -fallow-pch-with-compiler-errors
47+
// RUN: c-index-test -index-file %s -include %t-clang.h -Xclang -detailed-preprocessing-record | FileCheck -check-prefix=CHECK-INDEX %s

0 commit comments

Comments
 (0)