From: Argyrios Kyrtzidis Date: Mon, 27 Feb 2017 03:52:36 +0000 (+0000) Subject: [GeneratePCHAction] If preprocessor option 'AllowPCHWithCompilerErrors' is enabled... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=870fa3969cf0e9e914b21be0b8351f4b8b907eae;p=clang [GeneratePCHAction] If preprocessor option 'AllowPCHWithCompilerErrors' is enabled, don't delete the produced PCH file if error diagnostics occurred. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296320 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h index 20fddc4d5a..778b40b15d 100644 --- a/include/clang/Frontend/FrontendActions.h +++ b/include/clang/Frontend/FrontendActions.h @@ -80,6 +80,8 @@ protected: bool hasASTFileSupport() const override { return false; } + bool shouldEraseOutputFiles() override; + public: /// \brief Compute the AST consumer arguments that will be used to /// create the PCHGenerator instance returned by CreateASTConsumer. diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index c475cf467a..bb4f5302ed 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -93,7 +93,7 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { Consumers.push_back(llvm::make_unique( CI.getPreprocessor(), OutputFile, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions, - /*AllowASTWithErrors*/false, + /*AllowASTWithErrors*/CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, /*IncludeTimestamps*/ +CI.getFrontendOpts().IncludeTimestamps)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( @@ -127,6 +127,12 @@ GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI, return OS; } +bool GeneratePCHAction::shouldEraseOutputFiles() { + if (getCompilerInstance().getPreprocessorOpts().AllowPCHWithCompilerErrors) + return false; + return ASTFrontendAction::shouldEraseOutputFiles(); +} + bool GeneratePCHAction::BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) { CI.getLangOpts().CompilingPCH = true; diff --git a/test/Index/pch-from-libclang.c b/test/Index/pch-from-libclang.c index f6ee81e0cd..349fcac01e 100644 --- a/test/Index/pch-from-libclang.c +++ b/test/Index/pch-from-libclang.c @@ -6,18 +6,21 @@ // RUN: %clang_cc1 -fsyntax-only %s -verify // RUN: c-index-test -write-pch %t.h.pch %s -fmodules -fmodules-cache-path=%t.mcp -Xclang -triple -Xclang x86_64-apple-darwin // RUN: %clang -fsyntax-only -include %t.h %s -Xclang -verify -fmodules -fmodules-cache-path=%t.mcp -Xclang -detailed-preprocessing-record -Xclang -triple -Xclang x86_64-apple-darwin -Xclang -fallow-pch-with-compiler-errors +// RUN: %clang -x c-header %s -o %t.clang.h.pch -fmodules -fmodules-cache-path=%t.mcp -Xclang -detailed-preprocessing-record -Xclang -triple -Xclang x86_64-apple-darwin -Xclang -fallow-pch-with-compiler-errors -Xclang -verify +// RUN: c-index-test -test-load-source local %s -include %t.clang.h -fmodules -fmodules-cache-path=%t.mcp -Xclang -triple -Xclang x86_64-apple-darwin | FileCheck %s #ifndef HEADER #define HEADER -struct S { int x; }; - void some_function(undeclared_type p); // expected-error{{unknown type name}} +struct S { int x; }; + #else // expected-no-diagnostics void test(struct S *s) { + // CHECK: [[@LINE+1]]:6: MemberRefExpr=x:[[@LINE-6]]:16 s->x = 0; }