summaryrefslogtreecommitdiff
path: root/clang-tools-extra/clangd/ClangdUnit.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-05-28 12:11:37 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-05-28 12:11:37 +0000
commit194406e244d05dab41de3936ec7f39ad41102586 (patch)
tree441b32845264a3c12263cf4b0da7337f5ccaeabd /clang-tools-extra/clangd/ClangdUnit.cpp
parent7d272111e0d0900bfbabe33431f8f9ff0c4748f5 (diff)
[clangd] Fix leak sanitizers warnings in clangd
The commit includes two changes: 1. Set DisableFree to false when building the ParsedAST. This is sane default, since clangd never wants to leak the AST. 2. Make sure CompilerInstance created in code completion is passed to the FrontendAction::BeginSourceFile call. We have to do this to make sure the memory buffers of remapped files are properly freed. Our tests do not produce any warnings under asan anymore. The changes are mostly trivial, just moving the code around. So sending without review.
Diffstat (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp')
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp
index 41f2df3669e..105bdb1fe8e 100644
--- a/clang-tools-extra/clangd/ClangdUnit.cpp
+++ b/clang-tools-extra/clangd/ClangdUnit.cpp
@@ -153,6 +153,10 @@ ParsedAST::Build(std::unique_ptr<clang::CompilerInvocation> CI,
std::unique_ptr<llvm::MemoryBuffer> Buffer,
std::shared_ptr<PCHContainerOperations> PCHs,
IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
+ assert(CI);
+ // Command-line parsing sets DisableFree to true by default, but we don't want
+ // to leak memory in clangd.
+ CI->getFrontendOpts().DisableFree = false;
const PrecompiledPreamble *PreamblePCH =
Preamble ? &Preamble->Preamble : nullptr;