Due to generated tokens expanded by macros, there can be multiple MacroExpansion fileid's, loop over them until we get to something real.

llvm-svn: 38590
diff --git a/clang/Basic/SourceManager.cpp b/clang/Basic/SourceManager.cpp
index 990a4a0..357adfd 100644
--- a/clang/Basic/SourceManager.cpp
+++ b/clang/Basic/SourceManager.cpp
@@ -135,7 +135,7 @@
   const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(FileID);
 
   // For Macros, the physical loc is specified by the MacroTokenFileID.
-  if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion)
+  while (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion)
     FIDInfo = &FileIDs[FIDInfo->u.MacroTokenFileID-1];
   
   return FIDInfo->IncludeLoc;
@@ -151,9 +151,10 @@
   
   // If this is a macro, we need to get the instantiation location.
   const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(FileID);
-  if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
+  while (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
     Loc = FIDInfo->IncludeLoc;
     FileID = Loc.getFileID();
+    FIDInfo = getFIDInfo(FileID);
   }
   
   unsigned FilePos = getFilePos(Loc);
@@ -175,7 +176,7 @@
   
   // If this is a macro, we need to get the instantiation location.
   const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(FileID);
-  if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
+  while (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
     Loc = FIDInfo->IncludeLoc;
     FIDInfo = getFIDInfo(Loc.getFileID());
   }
@@ -192,7 +193,7 @@
   unsigned FileID = Loc.getFileID();
   // If this is a macro, we need to get the instantiation location.
   const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(FileID);
-  if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
+  while (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
     Loc = FIDInfo->IncludeLoc;
     FileID = Loc.getFileID();
     FIDInfo = getFIDInfo(FileID);
@@ -270,8 +271,10 @@
  
   // If this is a macro, we need to get the instantiation location.
   const SrcMgr::FileIDInfo *FIDInfo = getFIDInfo(Loc.getFileID());
-  if (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion)
-    return getFilePos(FIDInfo->IncludeLoc);
+  while (FIDInfo->IDType == SrcMgr::FileIDInfo::MacroExpansion) {
+    Loc = FIDInfo->IncludeLoc;
+    FIDInfo = getFIDInfo(Loc.getFileID());
+  }
   
   return getFilePos(Loc);
 }