@@ -431,7 +431,7 @@ struct MappedLoc {
431431class IndexSwiftASTWalker : public SourceEntityWalker {
432432 IndexDataConsumer &IdxConsumer;
433433 SourceManager &SrcMgr;
434- unsigned BufferID;
434+ std::optional< unsigned > BufferID;
435435 bool enableWarnings;
436436
437437 ModuleDecl *CurrentModule = nullptr ;
@@ -592,7 +592,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
592592 IndexSwiftASTWalker (IndexDataConsumer &IdxConsumer, ASTContext &Ctx,
593593 SourceFile *SF = nullptr )
594594 : IdxConsumer(IdxConsumer), SrcMgr(Ctx.SourceMgr),
595- BufferID (SF ? SF->getBufferID () : -1 ),
595+ BufferID (SF ? std::optional( SF->getBufferID ()) : std::nullopt ),
596596 enableWarnings(IdxConsumer.enableWarnings()) {}
597597
598598 ~IndexSwiftASTWalker () override {
@@ -1066,19 +1066,19 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
10661066 // \c None if \p loc is otherwise invalid or its original location isn't
10671067 // contained within the current buffer.
10681068 std::optional<MappedLoc> getMappedLocation (SourceLoc loc) {
1069- if (loc.isInvalid ()) {
1069+ if (loc.isInvalid () || !BufferID. has_value () ) {
10701070 if (IsModuleFile)
10711071 return {{0 , 0 , false }};
10721072 return std::nullopt ;
10731073 }
10741074
1075+ auto bufferID = BufferID.value ();
10751076 bool inGeneratedBuffer =
1076- !SrcMgr.rangeContainsTokenLoc (SrcMgr.getRangeForBuffer (BufferID ), loc);
1077+ !SrcMgr.rangeContainsTokenLoc (SrcMgr.getRangeForBuffer (bufferID ), loc);
10771078
1078- auto bufferID = BufferID;
10791079 if (inGeneratedBuffer) {
10801080 std::tie (bufferID, loc) = CurrentModule->getOriginalLocation (loc);
1081- if (BufferID != bufferID) {
1081+ if (BufferID. value () != bufferID) {
10821082 assert (false && " Location is not within file being indexed" );
10831083 return std::nullopt ;
10841084 }
0 commit comments