Skip to content

Commit 0e1cc08

Browse files
authored
DocComment API: ensure LineList does not outlive the MarkupContext and SourceManager it depends on. (#8102)
1 parent 3bd3eeb commit 0e1cc08

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/IDE/CommentConversion.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,10 @@ static void replaceObjcDeclarationsWithSwiftOnes(const Decl *D,
397397
OS << Doc;
398398
}
399399

400-
static LineList getLineListFromComment(const StringRef Text) {
400+
static LineList getLineListFromComment(SourceManager &SourceMgr,
401+
swift::markup::MarkupContext &MC,
402+
const StringRef Text) {
401403
LangOptions LangOpts;
402-
SourceManager SourceMgr;
403404
auto Tokens = swift::tokenize(LangOpts, SourceMgr,
404405
SourceMgr.addMemBufferCopy(Text));
405406
std::vector<SingleRawComment> Comments;
@@ -413,12 +414,13 @@ static LineList getLineListFromComment(const StringRef Text) {
413414
return {};
414415

415416
RawComment Comment(Comments);
416-
swift::markup::MarkupContext MC;
417417
return MC.getLineList(Comment);
418418
}
419419

420420
std::string ide::extractPlainTextFromComment(const StringRef Text) {
421-
return getLineListFromComment(Text).str();
421+
SourceManager SourceMgr;
422+
swift::markup::MarkupContext MC;
423+
return getLineListFromComment(SourceMgr, MC, Text).str();
422424
}
423425

424426
bool ide::getDocumentationCommentAsXML(const Decl *D, raw_ostream &OS) {
@@ -467,8 +469,9 @@ bool ide::convertMarkupToXML(StringRef Text, raw_ostream &OS) {
467469
llvm::raw_string_ostream OS(Comment);
468470
OS << "/**\n" << Text << "\n" << "*/";
469471
}
470-
LineList LL = getLineListFromComment(Comment);
472+
SourceManager SourceMgr;
471473
MarkupContext MC;
474+
LineList LL = getLineListFromComment(SourceMgr, MC, Comment);
472475
if (auto *Doc = swift::markup::parseDocument(MC, LL)) {
473476
CommentToXMLConverter Converter(OS);
474477
Converter.visitCommentParts(extractCommentParts(MC, Doc));

0 commit comments

Comments
 (0)