Skip to content

Commit 6ad0977

Browse files
author
Harlan Haskins
committed
Ensure the SourceManager outlives the RawSyntax tree to avoid deallocating strings
1 parent da87ab8 commit 6ad0977

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: tools/swift-syntax-test/swift-syntax-test.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void anchorForGetMainExecutable() {}
104104

105105
int getSyntaxTree(const char *MainExecutablePath,
106106
const StringRef InputFilename,
107+
CompilerInstance &Instance,
107108
llvm::SmallVectorImpl<syntax::Syntax> &TopLevelDecls,
108109
std::vector<std::pair<RC<syntax::TokenSyntax>,
109110
syntax::AbsolutePosition>> &Tokens) {
@@ -115,7 +116,6 @@ int getSyntaxTree(const char *MainExecutablePath,
115116
reinterpret_cast<void *>(&anchorForGetMainExecutable)));
116117

117118
Invocation.setModuleName("Test");
118-
CompilerInstance Instance;
119119

120120
auto &SourceMgr = Instance.getSourceMgr();
121121

@@ -219,8 +219,10 @@ int doFullParseRoundTrip(const char *MainExecutablePath,
219219
llvm::SmallVector<syntax::Syntax, 10> TopLevelDecls;
220220
std::vector<std::pair<RC<syntax::TokenSyntax>,
221221
syntax::AbsolutePosition>> Tokens;
222+
CompilerInstance Instance;
222223

223-
getSyntaxTree(MainExecutablePath, InputFilename, TopLevelDecls, Tokens);
224+
getSyntaxTree(MainExecutablePath, InputFilename, Instance,
225+
TopLevelDecls, Tokens);
224226

225227
for (auto &Node : TopLevelDecls) {
226228
Node.print(llvm::outs());
@@ -239,8 +241,10 @@ int doSerializeRawTree(const char *MainExecutablePath,
239241
llvm::SmallVector<syntax::Syntax, 10> TopLevelDecls;
240242
std::vector<std::pair<RC<syntax::TokenSyntax>,
241243
syntax::AbsolutePosition>> Tokens;
244+
CompilerInstance Instance;
242245

243-
getSyntaxTree(MainExecutablePath, InputFilename, TopLevelDecls, Tokens);
246+
getSyntaxTree(MainExecutablePath, InputFilename, Instance,
247+
TopLevelDecls, Tokens);
244248

245249
for (auto &Node : TopLevelDecls) {
246250
swift::json::Output out(llvm::outs());

0 commit comments

Comments
 (0)