Increase the macro id cache to look up several recent entries, not just the last one.
This is important in insane cases like the one dannyb sent me recently: #define F0(a) void a(){} #define F1(a) F0(a##0) F0(a##1) F0(a##2) F0(a##3) F0(a##4) F0(a##5) F0(a##6) F0(a##7) #define F2(a) F1(a##0) F1(a##1) F1(a##2) F1(a##3) F1(a##4) F1(a##5) F1(a##6) F1(a##7) #define F3(a) F2(a##0) F2(a##1) F2(a##2) F2(a##3) F2(a##4) F2(a##5) F2(a##6) F2(a##7) #define F4(a) F3(a##0) F3(a##1) F3(a##2) F3(a##3) F3(a##4) F3(a##5) F3(a##6) F3(a##7) #define F5(a) F4(a##0) F4(a##1) F4(a##2) F4(a##3) F4(a##4) F4(a##5) F4(a##6) F4(a##7) #define F6(a) F5(a##0) F5(a##1) F5(a##2) F5(a##3) F5(a##4) F5(a##5) F5(a##6) F5(a##7) F6(f) cpp is great. :) llvm-svn: 40715
This commit is contained in:
parent
e621b07e5e
commit
04e3d20a51
|
@ -178,19 +178,22 @@ SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc,
|
|||
|
||||
|
||||
// If the last macro id is close to the currently requested location, try to
|
||||
// reuse it. This implements a single-entry cache.
|
||||
if (!MacroIDs.empty()) {
|
||||
MacroIDInfo &LastOne = MacroIDs.back();
|
||||
// reuse it. This implements a small cache.
|
||||
for (int i = MacroIDs.size()-1, e = MacroIDs.size()-6; i >= 0 && i != e; --i){
|
||||
MacroIDInfo &LastOne = MacroIDs[i];
|
||||
|
||||
if (LastOne.getInstantiationLoc() == InstantLoc &&
|
||||
LastOne.getPhysicalLoc().getFileID() == PhysLoc.getFileID()) {
|
||||
// The instanitation point and source physloc have to exactly match to reuse
|
||||
// (for now). We could allow "nearby" instantiations in the future.
|
||||
if (LastOne.getInstantiationLoc() != InstantLoc ||
|
||||
LastOne.getPhysicalLoc().getFileID() != PhysLoc.getFileID())
|
||||
continue;
|
||||
|
||||
// Check to see if the physloc of the token came from near enough to reuse.
|
||||
int PhysDelta = PhysLoc.getRawFilePos() -
|
||||
LastOne.getPhysicalLoc().getRawFilePos();
|
||||
if (SourceLocation::isValidMacroPhysOffs(PhysDelta))
|
||||
return SourceLocation::getMacroLoc(MacroIDs.size()-1, PhysDelta, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MacroIDs.push_back(MacroIDInfo::get(InstantLoc, PhysLoc));
|
||||
|
|
Loading…
Reference in New Issue