15
15
#include " clang/Sema/MultiplexExternalSemaSource.h"
16
16
#include " clang/Sema/Sema.h"
17
17
#include " clang/Sema/SemaConsumer.h"
18
+ #include " llvm/ADT/IntrusiveRefCntPtr.h"
18
19
#include < optional>
19
20
20
21
namespace clang {
@@ -25,13 +26,15 @@ class Module;
25
26
26
27
namespace lldb_private {
27
28
28
- // / Wraps an ExternalASTSource into an ExternalSemaSource. Doesn't take
29
- // / ownership of the provided source.
29
+ // / Wraps an ExternalASTSource into an ExternalSemaSource.
30
+ // /
31
+ // / Assumes shared ownership of the underlying source.
30
32
class ExternalASTSourceWrapper : public ImporterBackedASTSource {
31
- ExternalASTSource * m_Source;
33
+ llvm::IntrusiveRefCntPtr< ExternalASTSource> m_Source;
32
34
33
35
public:
34
- ExternalASTSourceWrapper (ExternalASTSource *Source) : m_Source(Source) {
36
+ explicit ExternalASTSourceWrapper (ExternalASTSource *Source)
37
+ : m_Source(Source) {
35
38
assert (m_Source && " Can't wrap nullptr ExternalASTSource" );
36
39
}
37
40
@@ -257,10 +260,18 @@ class SemaSourceWithPriorities : public ImporterBackedASTSource {
257
260
// / Construct a SemaSourceWithPriorities with a 'high quality' source that
258
261
// / has the higher priority and a 'low quality' source that will be used
259
262
// / as a fallback.
260
- SemaSourceWithPriorities (clang::ExternalSemaSource &high_quality_source,
261
- clang::ExternalSemaSource &low_quality_source) {
262
- Sources.push_back (&high_quality_source);
263
- Sources.push_back (&low_quality_source);
263
+ // /
264
+ // / This class assumes shared ownership of the sources provided to it.
265
+ SemaSourceWithPriorities (clang::ExternalSemaSource *high_quality_source,
266
+ clang::ExternalSemaSource *low_quality_source) {
267
+ assert (high_quality_source);
268
+ assert (low_quality_source);
269
+
270
+ high_quality_source->Retain ();
271
+ low_quality_source->Retain ();
272
+
273
+ Sources.push_back (high_quality_source);
274
+ Sources.push_back (low_quality_source);
264
275
}
265
276
266
277
~SemaSourceWithPriorities () override ;
0 commit comments