[libSyntax] Make RawSyntaxCacheNode retain its underlying RawSyntax node

Previously RawSyntaxCacheNode was not increasing the RawSyntax refCount
and accessing a cached node would fail if the node had been deleted in
the meantime. We weren't hitting this so far, because all nodes were
allocated using a bump allocator and thus the underlying memory never
freed.
This commit is contained in:
Alex Hoppen
2018-08-10 17:21:08 -07:00
parent 1529d65748
commit e5c8440fe4

View File

@@ -75,16 +75,16 @@ class RawSyntaxCacheNode : public llvm::FoldingSetNode {
friend llvm::FoldingSetTrait<RawSyntaxCacheNode>;
/// Associated RawSyntax.
RawSyntax *Obj;
RC<RawSyntax> Obj;
/// FoldingSet node identifier of the associated RawSyntax.
llvm::FoldingSetNodeIDRef IDRef;
public:
RawSyntaxCacheNode(RawSyntax *Obj, const llvm::FoldingSetNodeIDRef IDRef)
RawSyntaxCacheNode(RC<RawSyntax> Obj, const llvm::FoldingSetNodeIDRef IDRef)
: Obj(Obj), IDRef(IDRef) {}
/// Retrieve assciated RawSyntax.
RawSyntax *get() { return Obj; }
RC<RawSyntax> get() { return Obj; }
// Only allow allocation of Node using the allocator in SyntaxArena.
void *operator new(size_t Bytes, SyntaxArena &Arena,
@@ -156,7 +156,7 @@ RC<RawSyntax> RawSyntax::getToken(SyntaxArena &Arena, tok TokKind,
auto Raw = RawSyntax::make(TokKind, Text, LeadingTrivia, TrailingTrivia,
SourcePresence::Present, &Arena);
auto IDRef = ID.Intern(Arena.getAllocator());
auto CacheNode = new (Arena) RawSyntaxCacheNode(Raw.get(), IDRef);
auto CacheNode = new (Arena) RawSyntaxCacheNode(Raw, IDRef);
CachedTokens.InsertNode(CacheNode, insertPos);
return Raw;
}