When we use `SemaSourceWithPriorities` as the `ASTContext`s ExternalASTSource, we allocate a `ClangASTSourceProxy` (via `CreateProxy`) and two `ExternalASTSourceWrapper`. Then we push these sources into a vector in `SemaSourceWithPriorities`. The allocated `SemaSourceWithPriorities` itself will get properly deallocated because the `ASTContext` wraps it in an `IntrusiveRefCntPtr`. But the three sources we allocated earlier will never get released. This patch fixes this by mimicking what `MultiplexExternalSemaSource` does (which is what `SemaSourceWithPriorities` is based on anyway). I.e., when `SemaSourceWithPriorities` gets constructed, it increments the use count of its sources. And on destruction it decrements them. Similarly, to make sure we dealloacted the `ClangASTProxy` properly, the `ExternalASTSourceWrapper` now assumes shared ownership of the underlying source.
30 lines
977 B
C++
30 lines
977 B
C++
//===-- ASTUtils.cpp ------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "ASTUtils.h"
|
|
|
|
lldb_private::ExternalASTSourceWrapper::~ExternalASTSourceWrapper() = default;
|
|
|
|
void lldb_private::ExternalASTSourceWrapper::PrintStats() {
|
|
m_Source->PrintStats();
|
|
}
|
|
|
|
lldb_private::ASTConsumerForwarder::~ASTConsumerForwarder() = default;
|
|
|
|
void lldb_private::ASTConsumerForwarder::PrintStats() { m_c->PrintStats(); }
|
|
|
|
lldb_private::SemaSourceWithPriorities::~SemaSourceWithPriorities() {
|
|
for (auto *Source : Sources)
|
|
Source->Release();
|
|
}
|
|
|
|
void lldb_private::SemaSourceWithPriorities::PrintStats() {
|
|
for (size_t i = 0; i < Sources.size(); ++i)
|
|
Sources[i]->PrintStats();
|
|
}
|