[PATCH] D149236: [clangd] Bail gracefully if given an assembly or IR source file
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 18 20:26:58 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG744b111434b2: [clangd] Bail gracefully if given an assembly or IR source file (authored by nridge).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149236/new/
https://reviews.llvm.org/D149236
Files:
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -13,6 +13,7 @@
#include "../../clang-tidy/ClangTidyCheck.h"
#include "AST.h"
+#include "CompileCommands.h"
#include "Compiler.h"
#include "Config.h"
#include "Diagnostics.h"
@@ -731,6 +732,37 @@
pragmaTrivia(" End")));
}
+TEST(ParsedASTTest, GracefulFailureOnAssemblyFile) {
+ std::string Filename = "TestTU.S";
+ std::string Code = R"S(
+main:
+ # test comment
+ bx lr
+ )S";
+
+ // The rest is a simplified version of TestTU::build().
+ // Don't call TestTU::build() itself because it would assert on
+ // failure to build an AST.
+ MockFS FS;
+ std::string FullFilename = testPath(Filename);
+ FS.Files[FullFilename] = Code;
+ ParseInputs Inputs;
+ auto &Argv = Inputs.CompileCommand.CommandLine;
+ Argv = {"clang"};
+ Argv.push_back(FullFilename);
+ Inputs.CompileCommand.Filename = FullFilename;
+ Inputs.CompileCommand.Directory = testRoot();
+ Inputs.Contents = Code;
+ Inputs.TFS = &FS;
+ StoreDiags Diags;
+ auto CI = buildCompilerInvocation(Inputs, Diags);
+ assert(CI && "Failed to build compilation invocation.");
+ auto AST = ParsedAST::build(FullFilename, Inputs, std::move(CI), {}, nullptr);
+
+ EXPECT_FALSE(AST.has_value())
+ << "Should not try to build AST for assembly source file";
+}
+
} // namespace
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/ParsedAST.cpp
===================================================================
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -396,6 +396,15 @@
VFS = Preamble->StatCache->getConsumingFS(std::move(VFS));
assert(CI);
+
+ if (CI->getFrontendOpts().Inputs.size() > 0) {
+ auto Lang = CI->getFrontendOpts().Inputs[0].getKind().getLanguage();
+ if (Lang == Language::Asm || Lang == Language::LLVM_IR) {
+ elog("Clangd does not support assembly or IR source files");
+ return std::nullopt;
+ }
+ }
+
// Command-line parsing sets DisableFree to true by default, but we don't want
// to leak memory in clangd.
CI->getFrontendOpts().DisableFree = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149236.551695.patch
Type: text/x-patch
Size: 2363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230819/26862daf/attachment.bin>
More information about the cfe-commits
mailing list