Author: Ben Langmuir
Date: 2020-03-31T13:50:12-07:00
New Revision: cc3fddb411d55d4d0902a772a9f3db11fc4f002e

URL: 
https://github.com/llvm/llvm-project/commit/cc3fddb411d55d4d0902a772a9f3db11fc4f002e
DIFF: 
https://github.com/llvm/llvm-project/commit/cc3fddb411d55d4d0902a772a9f3db11fc4f002e.diff

LOG: [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

Added: 
    

Modified: 
    clang/lib/Serialization/GeneratePCH.cpp
    clang/test/Index/pch-with-errors.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index 002233e49bb0..d869796b82c1 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -57,6 +57,11 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
     }
   }
 
+  // Errors that do not prevent the PCH from being written should not cause the
+  // overall compilation to fail either.
+  if (AllowASTWithErrors)
+    PP.getDiagnostics().getClient()->clear();
+
   // Emit the PCH file to the Buffer.
   assert(SemaPtr && "No Sema?");
   Buffer->Signature =

diff  --git a/clang/test/Index/pch-with-errors.c 
b/clang/test/Index/pch-with-errors.c
index 5c94a8a8e4d3..e8711c8e26a9 100644
--- a/clang/test/Index/pch-with-errors.c
+++ b/clang/test/Index/pch-with-errors.c
@@ -42,3 +42,6 @@ void foo(void) {
 
 // RUN: not c-index-test -write-pch %t.pch foobar.c 2>&1 | FileCheck 
-check-prefix=NONEXISTENT %s
 // NONEXISTENT: Unable to load translation unit
+
+// RUN: %clang -x c-header %s -o %t-clang.h.pch -Xclang 
-detailed-preprocessing-record -Xclang -fallow-pch-with-compiler-errors
+// RUN: c-index-test -index-file %s -include %t-clang.h -Xclang 
-detailed-preprocessing-record | FileCheck -check-prefix=CHECK-INDEX %s


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to