Provide a different fourth parameter to lower_bound. It was PPEntityComp, below and it seems like what you really want is a comparison function which only considers a subset of what PPEntityComp does. From: Argyrios Kyrtzidis Sent: Thursday, September 22, 2011 7:35 PM To: Ahmed Charles Cc: [email protected] Subject: Re: [cfe-commits] r140337 - in /cfe/trunk/lib: Lex/PreprocessingRecord.cpp Serialization/ASTReader.cpp On Sep 22, 2011, at 7:16 PM, Ahmed Charles wrote:
> Why not change the comparison function rather than write your own > binary search in two different places? How should I change the comparison function, could you elaborate ? > From: Argyrios Kyrtzidis > Sent: Thursday, September 22, 2011 2:20 PM > To: [email protected] > Subject: [cfe-commits] r140337 - in /cfe/trunk/lib: > Lex/PreprocessingRecord.cpp Serialization/ASTReader.cpp > Author: akirtzidis > Date: Thu Sep 22 16:17:02 2011 > New Revision: 140337 > > URL: http://llvm.org/viewvc/llvm-project?rev=140337&view=rev > Log: > Do manual binary search for preprocessing entities because their end locations > may be unordered and MSVC's debug-mode doesn't like it. > > Modified: > cfe/trunk/lib/Lex/PreprocessingRecord.cpp > cfe/trunk/lib/Serialization/ASTReader.cpp > > Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=140337&r1=140336&r2=140337&view=diff > ============================================================================== > --- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original) > +++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Thu Sep 22 16:17:02 2011 > @@ -129,12 +129,30 @@ > if (SourceMgr.isLoadedSourceLocation(Loc)) > return 0; > > + size_t Count = PreprocessedEntities.size(); > + size_t Half; > std::vector<PreprocessedEntity *>::const_iterator > - I = std::lower_bound(PreprocessedEntities.begin(), > - PreprocessedEntities.end(), > - Loc, > - PPEntityComp<&SourceRange::getEnd>(SourceMgr)); > - return I - PreprocessedEntities.begin(); > + First = PreprocessedEntities.begin(); > + std::vector<PreprocessedEntity *>::const_iterator I; > + > + // Do a binary search manually instead of using std::lower_bound because > + // The end locations of entities may be unordered (when a macro expansion > + // is inside another macro argument), but for this case it is not important > + // whether we get the first macro expansion or its containing macro. > + while (Count > 0) { > + Half = Count/2; > + I = First; > + std::advance(I, Half); > + if (SourceMgr.isBeforeInTranslationUnit((*I)->getSourceRange().getEnd(), > + Loc)){ > + First = I; > + ++First; > + Count = Count - Half - 1; > + } else > + Count = Half; > + } > + > + return First - PreprocessedEntities.begin(); > } > > unsigned PreprocessingRecord::findEndLocalPreprocessedEntity( > > Modified: cfe/trunk/lib/Serialization/ASTReader.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=140337&r1=140336&r2=140337&view=diff > ============================================================================== > --- cfe/trunk/lib/Serialization/ASTReader.cpp (original) > +++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Sep 22 16:17:02 2011 > @@ -2947,9 +2947,28 @@ > typedef const PPEntityOffset *pp_iterator; > pp_iterator pp_begin = M.PreprocessedEntityOffsets; > pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; > - pp_iterator PPI = > - std::lower_bound(pp_begin, pp_end, BLoc, > - PPEntityComp<&PPEntityOffset::End>(*this, M)); > + > + size_t Count = M.NumPreprocessedEntities; > + size_t Half; > + pp_iterator First = pp_begin; > + pp_iterator PPI; > + > + // Do a binary search manually instead of using std::lower_bound because > + // The end locations of entities may be unordered (when a macro expansion > + // is inside another macro argument), but for this case it is not important > + // whether we get the first macro expansion or its containing macro. > + while (Count > 0) { > + Half = Count/2; > + PPI = First; > + std::advance(PPI, Half); > + if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), > + BLoc)){ > + First = PPI; > + ++First; > + Count = Count - Half - 1; > + } else > + Count = Half; > + } > > if (PPI == pp_end) > return findNextPreprocessedEntity(SLocMapI); > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
