[libclang] Indexing API: Fix suppressing of references in macros and suppress
@class forward references.

rdar://10568080&10568103&10568119

llvm-svn: 146496
diff --git a/clang/tools/libclang/IndexingContext.cpp b/clang/tools/libclang/IndexingContext.cpp
index b95d22d..66e552c 100644
--- a/clang/tools/libclang/IndexingContext.cpp
+++ b/clang/tools/libclang/IndexingContext.cpp
@@ -228,7 +228,8 @@
   if (!DInfo.EntInfo.USR || Loc.isInvalid())
     return false;
 
-  markEntityOccurrenceInFile(D, Loc);
+  if (suppressRefs())
+    markEntityOccurrenceInFile(D, Loc);
   
   DInfo.entityInfo = &DInfo.EntInfo;
   DInfo.cursor = Cursor;
@@ -304,6 +305,12 @@
   SourceLocation Loc = Ref->getLocation();
   bool isRedeclaration = IFaceD->getLocation() != Loc;
  
+  // For @class forward declarations, suppress them the same way as references.
+  if (suppressRefs()) {
+    if (markEntityOccurrenceInFile(IFaceD, Loc))
+      return false; // already occurred.
+  }
+
   ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration,
                                   /*isImplementation=*/false);
   return handleObjCContainer(IFaceD, Loc,
@@ -373,6 +380,9 @@
                                                      : D->getCategoryNameLoc();
   getEntityInfo(IFaceD, ClassEntity, SA);
 
+  if (suppressRefs())
+    markEntityOccurrenceInFile(IFaceD, ClassLoc);
+
   CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
   if (IFaceD) {
     CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
@@ -583,10 +593,13 @@
 
 bool IndexingContext::markEntityOccurrenceInFile(const NamedDecl *D,
                                                  SourceLocation Loc) {
+  if (!D || Loc.isInvalid())
+    return true;
+
   SourceManager &SM = Ctx->getSourceManager();
   D = getEntityDecl(D);
   
-  std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
+  std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SM.getFileLoc(Loc));
   FileID FID = LocInfo.first;
   if (FID.isInvalid())
     return true;