[clang-tools-extra] ed33911 - [clangd] Always default to raw pch format
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Fri May 14 07:40:14 PDT 2021
Author: Kadir Cetinkaya
Date: 2021-05-14T16:34:57+02:00
New Revision: ed339111bff690c6ba87d5e25c50bcad6793a309
URL: https://github.com/llvm/llvm-project/commit/ed339111bff690c6ba87d5e25c50bcad6793a309
DIFF: https://github.com/llvm/llvm-project/commit/ed339111bff690c6ba87d5e25c50bcad6793a309.diff
LOG: [clangd] Always default to raw pch format
Clang would emit a fatal error when it encounters an unregistered PCH
format. This change ensures clangd will always use raw format no matter what
user specifies.
As side effects:
- serializing an AST in an unknown format might throw off build
systems. I suppose this would only be an issue when build system and clangd are
racing for same PCM modules, hopefully this should be rare and both clangd or
the build system should recover on the next run.
- whenever clang reads a serialized AST it seems to be checking for file
signature and emitting non-fatal errors. so this should be fine again.
The only other valid module format in clang is `obj` but it is part of codegen,
i don't think it is worth the dependency. Hence chosing to not register it, at
least yet.
Differential Revision: https://reviews.llvm.org/D102418
Added:
Modified:
clang-tools-extra/clangd/Compiler.cpp
clang-tools-extra/clangd/unittests/ModulesTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index 0a1e43d808643..a7e48934ddaf2 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -85,6 +85,11 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
// Don't crash on `#pragma clang __debug parser_crash`
CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
+ // Always default to raw container format as clangd doesn't registry any other
+ // and clang dies when faced with unknown formats.
+ CI->getHeaderSearchOpts().ModuleFormat =
+ PCHContainerOperations().getRawReader().getFormat().str();
+
return CI;
}
diff --git a/clang-tools-extra/clangd/unittests/ModulesTests.cpp b/clang-tools-extra/clangd/unittests/ModulesTests.cpp
index b56b91836508f..0fdc22c954336 100644
--- a/clang-tools-extra/clangd/unittests/ModulesTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ModulesTests.cpp
@@ -92,6 +92,24 @@ TEST(Modules, Diagnostic) {
TU.build();
}
+// Unknown module formats are a fatal failure for clang. Ensure we don't crash.
+TEST(Modules, UnknownFormat) {
+ TestTU TU = TestTU::withCode(R"(#include "modular.h")");
+ TU.OverlayRealFileSystemForModules = true;
+ TU.ExtraArgs.push_back("-Xclang");
+ TU.ExtraArgs.push_back("-fmodule-format=obj");
+ TU.ExtraArgs.push_back("-fmodule-map-file=" + testPath("m.modulemap"));
+ TU.ExtraArgs.push_back("-fmodules");
+ TU.ExtraArgs.push_back("-fimplicit-modules");
+ TU.AdditionalFiles["modular.h"] = "";
+ TU.AdditionalFiles["m.modulemap"] = R"modulemap(
+ module M {
+ header "modular.h"
+ })modulemap";
+
+ // Test that we do not crash.
+ TU.build();
+}
} // namespace
} // namespace clangd
} // namespace clang
More information about the cfe-commits
mailing list