File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed
tools/SourceKit/lib/SwiftLang Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ class SwiftInterfaceGenContext::Implementation {
68
68
std::string Text;
69
69
std::vector<TextReference> References;
70
70
std::vector<TextDecl> Decls;
71
+ // / Do not clear the map or erase elements, without keeping the Decls vector in sync
71
72
llvm::StringMap<TextDecl> USRMap;
72
73
};
73
74
@@ -160,6 +161,9 @@ class AnnotatingPrinter : public StreamPrinter {
160
161
DeclUSRs.emplace_back (VD, USR);
161
162
auto iterator = Info.USRMap .insert_or_assign (USR, Entry).first ;
162
163
// Set the USR in the declarations to the key in the USRMap, because the lifetime of that matches/exceeds the lifetime of Decls
164
+ // String keys in the StringMap are heap allocated and only get destroyed on explicit erase() or clear() calls, or on destructor calls
165
+ // (the ProgrammersManual description itself also states that StringMap "only ever copies a string if a value is inserted").
166
+ // Thus this never results in a dangling reference, as the USRMap is never cleared and no elements are erased in its lifetime.
163
167
Info.Decls .back ().USR = iterator->getKey ();
164
168
}
165
169
}
You can’t perform that action at this time.
0 commit comments