Explicitly link macro instantiations to macro definitions in the
preprocessing record. Use that link with clang_getCursorReferenced()
and clang_getCursorDefinition() to match instantiations of a macro to
the definition of the macro.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98842 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index ce21885..47d156c 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -1765,6 +1765,11 @@
     return clang_getNullCursor();
   }
 
+  if (C.kind == CXCursor_MacroInstantiation) {
+    if (MacroDefinition *Def = getCursorMacroInstantiation(C)->getDefinition())
+      return MakeMacroDefinitionCursor(Def, CXXUnit);
+  }
+
   if (!clang_isReference(C.kind))
     return clang_getNullCursor();
 
@@ -1803,6 +1808,9 @@
     WasReference = true;
   }
 
+  if (C.kind == CXCursor_MacroInstantiation)
+    return clang_getCursorReferenced(C);
+
   if (!clang_isDeclaration(C.kind))
     return clang_getNullCursor();