summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-22 21:17:02 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-22 21:17:02 +0000
commite523e389b2a2a91fde6c5e317ca0fcd4eef3cccd (patch)
treef7d8370ae31da706cbefe4de2df3308ae29b0e89 /clang/lib/Lex
parent8c4b716352b4f8b848b426ce3068b58590e9ce55 (diff)
downloadbcm5719-llvm-e523e389b2a2a91fde6c5e317ca0fcd4eef3cccd.tar.gz
bcm5719-llvm-e523e389b2a2a91fde6c5e317ca0fcd4eef3cccd.zip
Do manual binary search for preprocessing entities because their end locations
may be unordered and MSVC's debug-mode doesn't like it. llvm-svn: 140337
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/PreprocessingRecord.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp
index 438eba00ba3..0f5577520d6 100644
--- a/clang/lib/Lex/PreprocessingRecord.cpp
+++ b/clang/lib/Lex/PreprocessingRecord.cpp
@@ -129,12 +129,30 @@ unsigned PreprocessingRecord::findBeginLocalPreprocessedEntity(
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(
OpenPOWER on IntegriCloud