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"
19
+ #include " llvm/Support/Casting.h"
18
20
#include < optional>
19
21
20
22
namespace clang {
@@ -25,13 +27,15 @@ class Module;
25
27
26
28
namespace lldb_private {
27
29
28
- // / Wraps an ExternalASTSource into an ExternalSemaSource. Doesn't take
29
- // / ownership of the provided source.
30
+ // / Wraps an ExternalASTSource into an ExternalSemaSource.
31
+ // /
32
+ // / Assumes shared ownership of the underlying source.
30
33
class ExternalASTSourceWrapper : public ImporterBackedASTSource {
31
- ExternalASTSource * m_Source;
34
+ llvm::IntrusiveRefCntPtr< ExternalASTSource> m_Source;
32
35
33
36
public:
34
- ExternalASTSourceWrapper (ExternalASTSource *Source) : m_Source(Source) {
37
+ explicit ExternalASTSourceWrapper (ExternalASTSource *Source)
38
+ : m_Source(Source) {
35
39
assert (m_Source && " Can't wrap nullptr ExternalASTSource" );
36
40
}
37
41
@@ -136,6 +140,24 @@ class ExternalASTSourceWrapper : public ImporterBackedASTSource {
136
140
return m_Source->layoutRecordType (Record, Size, Alignment, FieldOffsets,
137
141
BaseOffsets, VirtualBaseOffsets);
138
142
}
143
+
144
+ // / This gets called when Sema is reconciling undefined but used decls.
145
+ // / For LLDB's use-case, we never provide Clang with function definitions,
146
+ // / instead we rely on linkage names and symbol resolution to call the
147
+ // / correct funcitons during JITting. So this implementation clears
148
+ // / any "undefined" FunctionDecls that Clang found while parsing.
149
+ // /
150
+ // / \param[in,out] Undefined A set of used decls for which Clang has not
151
+ // / been provided a definition with.
152
+ // /
153
+ void ReadUndefinedButUsed (
154
+ llvm::MapVector<clang::NamedDecl *, clang::SourceLocation> &Undefined)
155
+ override {
156
+ Undefined.remove_if ([](auto const &decl_loc_pair) {
157
+ const clang::NamedDecl *ND = decl_loc_pair.first ;
158
+ return llvm::isa_and_present<clang::FunctionDecl>(ND);
159
+ });
160
+ }
139
161
};
140
162
141
163
// / Wraps an ASTConsumer into an SemaConsumer. Doesn't take ownership of the
@@ -257,10 +279,18 @@ class SemaSourceWithPriorities : public ImporterBackedASTSource {
257
279
// / Construct a SemaSourceWithPriorities with a 'high quality' source that
258
280
// / has the higher priority and a 'low quality' source that will be used
259
281
// / 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);
282
+ // /
283
+ // / This class assumes shared ownership of the sources provided to it.
284
+ SemaSourceWithPriorities (clang::ExternalSemaSource *high_quality_source,
285
+ clang::ExternalSemaSource *low_quality_source) {
286
+ assert (high_quality_source);
287
+ assert (low_quality_source);
288
+
289
+ high_quality_source->Retain ();
290
+ low_quality_source->Retain ();
291
+
292
+ Sources.push_back (high_quality_source);
293
+ Sources.push_back (low_quality_source);
264
294
}
265
295
266
296
~SemaSourceWithPriorities () override ;
0 commit comments