Skip to content

Commit 4768de0

Browse files
author
Nathan Hawes
authored
Merge pull request swiftlang#35985 from nathawes/fix-cursor-info-parent-contexts-asan
[CusorInfo] Fix ASAN heap-use-after-free failure when reporting parent contexts.
2 parents d652ba0 + bba7029 commit 4768de0

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

test/SourceKit/CursorInfo/cursor_symbol_graph_parents.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: rdar74150023
2-
31
/// Something about variable global
42
let global = 1
53

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,7 @@ static bool passCursorInfoForDecl(SourceFile* SF,
836836

837837

838838
SmallVector<symbolgraphgen::PathComponent, 4> PathComponents;
839-
SmallVector<ParentInfo, 4> Parents;
840839
unsigned SymbolGraphBegin = SS.size();
841-
unsigned SymbolGraphEnd = SymbolGraphBegin;
842840
if (SymbolGraph) {
843841
symbolgraphgen::SymbolGraphOptions Options {
844842
"",
@@ -851,16 +849,16 @@ static bool passCursorInfoForDecl(SourceFile* SF,
851849
symbolgraphgen::printSymbolGraphForDecl(VD, BaseType,
852850
InSynthesizedExtension, Options, OS,
853851
PathComponents);
854-
SymbolGraphEnd = SS.size();
855-
856-
for (auto &Component: PathComponents) {
857-
unsigned USRStart = SS.size();
858-
if (SwiftLangSupport::printUSR(Component.VD, OS))
859-
continue;
860-
StringRef USR{SS.begin()+USRStart, SS.size() - USRStart};
861-
Parents.push_back({Component.Title, Component.Kind, USR});
862-
}
863852
}
853+
unsigned SymbolGraphEnd = SS.size();
854+
855+
DelayedStringRetriever ParentUSRsOS(SS);
856+
for (auto &Component: PathComponents) {
857+
ParentUSRsOS.startPiece();
858+
if (SwiftLangSupport::printUSR(Component.VD, OS))
859+
ParentUSRsOS.startPiece(); // ignore any output if invalid
860+
ParentUSRsOS.endPiece();
861+
};
864862

865863
unsigned FullDeclBegin = SS.size();
866864
{
@@ -995,6 +993,15 @@ static bool passCursorInfoForDecl(SourceFile* SF,
995993
StringRef SymbolGraphJSON = StringRef(SS.begin()+SymbolGraphBegin,
996994
SymbolGraphEnd-SymbolGraphBegin);
997995

996+
SmallVector<ParentInfo, 4> Parents;
997+
auto ParentIt = PathComponents.begin();
998+
ParentUSRsOS.retrieve([&](StringRef ParentUSR) {
999+
assert(ParentIt != PathComponents.end());
1000+
if (!ParentUSR.empty())
1001+
Parents.push_back({ParentIt->Title, ParentIt->Kind, ParentUSR});
1002+
++ParentIt;
1003+
});
1004+
9981005
// If VD is the syntehsized property wrapper backing storage (_foo) or
9991006
// projected value ($foo) of a property (foo), base the location on that
10001007
// property instead.

0 commit comments

Comments
 (0)