Fix PR9279 - Macro expansion stack trace seriously broken with function-style macros, by not recursively printing notes for other 'instantiated from' notes.

This is a one line fix here:
+      // Don't print recursive instantiation notes from an instantiation note.
+      Loc = SM.getSpellingLoc(Loc);

While here, fix the testcase to be more precise (it got filecheck'ized
brutally), and fix EmitCaretDiagnostic to be private and to not pass down
the unused 'Level' argument.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133993 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 76f2f3e..affa12b 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -292,8 +292,7 @@
   }
 }
 
-void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
-                                                SourceLocation Loc,
+void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
                                                 CharSourceRange *Ranges,
                                                 unsigned NumRanges,
                                                 const SourceManager &SM,
@@ -314,10 +313,10 @@
     bool Suppressed 
       = OnMacroInst >= MacroSkipStart && OnMacroInst < MacroSkipEnd;
     
-
     SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first;
+    
     // FIXME: Map ranges?
-    EmitCaretDiagnostic(Level, OneLevelUp, Ranges, NumRanges, SM,
+    EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM,
                         Hints, NumHints, Columns,
                         OnMacroInst + 1, MacroSkipStart, MacroSkipEnd);
     
@@ -356,7 +355,10 @@
       }
       OS << "note: instantiated from:\n";
       
-      EmitCaretDiagnostic(Level, Loc, Ranges, NumRanges, SM, 0, 0,
+      // Don't print recursive instantiation notes from an instantiation note.
+      Loc = SM.getSpellingLoc(Loc);
+
+      EmitCaretDiagnostic(Loc, Ranges, NumRanges, SM, 0, 0,
                           Columns, OnMacroInst + 1, MacroSkipStart,
                           MacroSkipEnd);
       return;
@@ -371,7 +373,7 @@
     
     return;
   }
-
+  
   // Decompose the location into a FID/Offset pair.
   std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
   FileID FID = LocInfo.first;
@@ -1059,7 +1061,7 @@
       }
     }        
     
-    EmitCaretDiagnostic(Level, LastLoc, Ranges, NumRanges, LastLoc.getManager(),
+    EmitCaretDiagnostic(LastLoc, Ranges, NumRanges, LastLoc.getManager(),
                         Info.getFixItHints(),
                         Info.getNumFixItHints(),
                         DiagOpts->MessageLength,