File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -189,21 +189,29 @@ void TokenBuffer::indexExpandedTokens() {
189
189
return ;
190
190
ExpandedTokIndex.reserve (ExpandedTokens.size ());
191
191
// Index ExpandedTokens for faster lookups by SourceLocation.
192
- for (size_t I = 0 , E = ExpandedTokens.size (); I != E; ++I)
193
- ExpandedTokIndex[ExpandedTokens[I].location ()] = I;
192
+ for (size_t I = 0 , E = ExpandedTokens.size (); I != E; ++I) {
193
+ SourceLocation Loc = ExpandedTokens[I].location ();
194
+ if (Loc.isValid ())
195
+ ExpandedTokIndex[Loc] = I;
196
+ }
194
197
}
195
198
196
199
llvm::ArrayRef<syntax::Token> TokenBuffer::expandedTokens (SourceRange R) const {
200
+ if (R.isInvalid ())
201
+ return {};
197
202
if (!ExpandedTokIndex.empty ()) {
198
203
// Quick lookup if `R` is a token range.
199
204
// This is a huge win since majority of the users use ranges provided by an
200
205
// AST. Ranges in AST are token ranges from expanded token stream.
201
206
const auto B = ExpandedTokIndex.find (R.getBegin ());
202
207
const auto E = ExpandedTokIndex.find (R.getEnd ());
203
208
if (B != ExpandedTokIndex.end () && E != ExpandedTokIndex.end ()) {
209
+ const Token *L = ExpandedTokens.data () + B->getSecond ();
204
210
// Add 1 to End to make a half-open range.
205
- return {ExpandedTokens.data () + B->getSecond (),
206
- ExpandedTokens.data () + E->getSecond () + 1 };
211
+ const Token *R = ExpandedTokens.data () + E->getSecond () + 1 ;
212
+ if (L > R)
213
+ return {};
214
+ return {L, R};
207
215
}
208
216
}
209
217
// Slow case. Use `isBeforeInTranslationUnit` to binary search for the
You can’t perform that action at this time.
0 commit comments