Skip to content

Commit e5c8440

Browse files
committed
[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.
1 parent 1529d65 commit e5c8440

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/Syntax/SyntaxArena.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ class RawSyntaxCacheNode : public llvm::FoldingSetNode {
7575
friend llvm::FoldingSetTrait<RawSyntaxCacheNode>;
7676

7777
/// Associated RawSyntax.
78-
RawSyntax *Obj;
78+
RC<RawSyntax> Obj;
7979
/// FoldingSet node identifier of the associated RawSyntax.
8080
llvm::FoldingSetNodeIDRef IDRef;
8181

8282
public:
83-
RawSyntaxCacheNode(RawSyntax *Obj, const llvm::FoldingSetNodeIDRef IDRef)
83+
RawSyntaxCacheNode(RC<RawSyntax> Obj, const llvm::FoldingSetNodeIDRef IDRef)
8484
: Obj(Obj), IDRef(IDRef) {}
8585

8686
/// Retrieve assciated RawSyntax.
87-
RawSyntax *get() { return Obj; }
87+
RC<RawSyntax> get() { return Obj; }
8888

8989
// Only allow allocation of Node using the allocator in SyntaxArena.
9090
void *operator new(size_t Bytes, SyntaxArena &Arena,
@@ -156,7 +156,7 @@ RC<RawSyntax> RawSyntax::getToken(SyntaxArena &Arena, tok TokKind,
156156
auto Raw = RawSyntax::make(TokKind, Text, LeadingTrivia, TrailingTrivia,
157157
SourcePresence::Present, &Arena);
158158
auto IDRef = ID.Intern(Arena.getAllocator());
159-
auto CacheNode = new (Arena) RawSyntaxCacheNode(Raw.get(), IDRef);
159+
auto CacheNode = new (Arena) RawSyntaxCacheNode(Raw, IDRef);
160160
CachedTokens.InsertNode(CacheNode, insertPos);
161161
return Raw;
162162
}

0 commit comments

Comments
 (0)