[llvm-branch-commits] [clang-tools-extra] cb89646 - [clangd] Filter pch related flags coming from the user

Sam McCall via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jun 10 04:55:06 PDT 2020


Author: Kadir Cetinkaya
Date: 2020-06-10T13:53:27+02:00
New Revision: cb89646a4a888b8721adbc746e167f31fd484c11

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

LOG: [clangd] Filter pch related flags coming from the user

Summary:
PCH format is unstable, hence using a preamble built with a different
version of clang (or even worse, a different compiler) might result in
unexpected behaviour.

PCH creation on the other hand is something clangd wouldn't want to perform, as
it doesn't generate any output files.

This patch makes sure clangd drops any PCH related compile commands after
parsing the command line args.

Fixes https://github.com/clangd/clangd/issues/248

Reviewers: sammccall

Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79669

(cherry picked from commit 35d867a790c2bcf2008b2ee1895ae8af2793b797)

Dropped the test as it depends on nontrivial changes from master.
The code is very simple and identical to that tested on master.

Fixes https://github.com/clangd/clangd/issues/419

Added: 
    

Modified: 
    clang-tools-extra/clangd/Compiler.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index 47cec5ae12e8..f4a913708ef7 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -41,8 +41,7 @@ void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
 }
 
 std::unique_ptr<CompilerInvocation>
-buildCompilerInvocation(const ParseInputs &Inputs,
-                        clang::DiagnosticConsumer &D,
+buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
                         std::vector<std::string> *CC1Args) {
   std::vector<const char *> ArgStrs;
   for (const auto &S : Inputs.CompileCommand.CommandLine)
@@ -74,6 +73,15 @@ buildCompilerInvocation(const ParseInputs &Inputs,
   CI->getDependencyOutputOpts().HeaderIncludeOutputFile.clear();
   CI->getDependencyOutputOpts().DOTOutputFile.clear();
   CI->getDependencyOutputOpts().ModuleDependencyOutputDir.clear();
+
+  // Disable any pch generation/usage operations. Since serialized preamble
+  // format is unstable, using an incompatible one might result in unexpected
+  // behaviours, including crashes.
+  CI->getPreprocessorOpts().ImplicitPCHInclude.clear();
+  CI->getPreprocessorOpts().PrecompiledPreambleBytes = {0, false};
+  CI->getPreprocessorOpts().PCHThroughHeader.clear();
+  CI->getPreprocessorOpts().PCHWithHdrStop = false;
+  CI->getPreprocessorOpts().PCHWithHdrStopCreate = false;
   return CI;
 }
 


        


More information about the llvm-branch-commits mailing list