[PATCH] D92646: [Tooling] JSONCompilationDatabase::loadFromBuffer retains the buffer, copy it.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 4 02:34:50 PST 2020
sammccall created this revision.
sammccall added a reviewer: usaxena95.
Herald added a subscriber: kadircet.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.
This function doesn't seem to be used in-tree outside tests.
However clangd wants to use it soon, and having the CDB be self-contained seems
reasonable.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92646
Files:
clang/lib/Tooling/JSONCompilationDatabase.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp
Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===================================================================
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -172,13 +172,15 @@
}
static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName,
- StringRef JSONDatabase,
+ std::string JSONDatabase,
std::string &ErrorMessage) {
std::unique_ptr<CompilationDatabase> Database(
JSONCompilationDatabase::loadFromBuffer(JSONDatabase, ErrorMessage,
JSONCommandLineSyntax::Gnu));
if (!Database)
return CompileCommand();
+ // Overwrite the string to verify we're not reading from it later.
+ JSONDatabase.assign(JSONDatabase.size(), '*');
std::vector<CompileCommand> Commands = Database->getCompileCommands(FileName);
EXPECT_LE(Commands.size(), 1u);
if (Commands.empty())
Index: clang/lib/Tooling/JSONCompilationDatabase.cpp
===================================================================
--- clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -217,7 +217,7 @@
std::string &ErrorMessage,
JSONCommandLineSyntax Syntax) {
std::unique_ptr<llvm::MemoryBuffer> DatabaseBuffer(
- llvm::MemoryBuffer::getMemBuffer(DatabaseString));
+ llvm::MemoryBuffer::getMemBufferCopy(DatabaseString));
std::unique_ptr<JSONCompilationDatabase> Database(
new JSONCompilationDatabase(std::move(DatabaseBuffer), Syntax));
if (!Database->parse(ErrorMessage))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92646.309494.patch
Type: text/x-patch
Size: 1811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201204/63af5f9e/attachment.bin>
More information about the cfe-commits
mailing list