aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/CompilationDatabaseTest.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2020-12-04 11:34:30 +0100
committerSam McCall <sam.mccall@gmail.com>2020-12-04 21:54:55 +0100
commit650e04e179c9d355cd6d8f9a108d60c7969d24ca (patch)
tree9faee16e84b4c3b2462728b1b30bc761be588cbe /clang/unittests/Tooling/CompilationDatabaseTest.cpp
parentd10f9863a5ac1cb681af07719650c44b48f289ce (diff)
downloadllvm-650e04e179c9d355cd6d8f9a108d60c7969d24ca.zip
llvm-650e04e179c9d355cd6d8f9a108d60c7969d24ca.tar.gz
llvm-650e04e179c9d355cd6d8f9a108d60c7969d24ca.tar.bz2
[Tooling] JSONCompilationDatabase::loadFromBuffer retains the buffer, copy it.
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. Differential Revision: https://reviews.llvm.org/D92646
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r--clang/unittests/Tooling/CompilationDatabaseTest.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 9e23428..168a1d6 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -172,13 +172,15 @@ TEST(JSONCompilationDatabase, GetAllCompileCommands) {
}
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())