Use PresumedLoc when emitting the 'included from' diagnostics.  For a malformed
test like this:

#line 4 "foo"

#define XX ?

#if XX
#endif

We now emit:

In file included from t.c:7:
foo:7:5: error: invalid token at start of a preprocessor expression
#if XX
    ^
foo:5:12: note: instantiated from:
#define XX ?
           ^

instead of:

In file included from t.c:7:
foo:7:5: error: invalid token at start of a preprocessor expression
#if XX
    ^
./t.h:6:12: note: instantiated from:
#define XX ?
           ^

(where the note doesn't obey #line or print the include stack when needed).

This fixes PR5617



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90554 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 6ab0e16..52a0f48 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -279,13 +279,14 @@
   assert(!Loc.isInvalid() && "must have a valid source location here");
 
   // If this is a macro ID, first emit information about where this was
-  // instantiated (recursively) then emit information about where. the token was
+  // instantiated (recursively) then emit information about where the token was
   // spelled from.
   if (!Loc.isFileID()) {
     SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first;
     // FIXME: Map ranges?
     EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM, 0, 0, Columns);
 
+    // Map the location.
     Loc = SM.getImmediateSpellingLoc(Loc);
 
     // Map the ranges.
@@ -295,15 +296,22 @@
       if (E.isMacroID()) E = SM.getImmediateSpellingLoc(E);
       Ranges[i] = SourceRange(S, E);
     }
+    
+    // Get the pretty name, according to #line directives etc.
+    PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+    
+    // If this diagnostic is not in the main file, print out the "included from"
+    // lines.
+    if (LastWarningLoc != PLoc.getIncludeLoc()) {
+      LastWarningLoc = PLoc.getIncludeLoc();
+      PrintIncludeStack(LastWarningLoc, SM);
+    }
 
     if (DiagOpts->ShowLocation) {
-      std::pair<FileID, unsigned> IInfo = SM.getDecomposedInstantiationLoc(Loc);
-
       // Emit the file/line/column that this expansion came from.
-      OS << SM.getBuffer(IInfo.first)->getBufferIdentifier() << ':'
-         << SM.getLineNumber(IInfo.first, IInfo.second) << ':';
+      OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':';
       if (DiagOpts->ShowColumn)
-        OS << SM.getColumnNumber(IInfo.first, IInfo.second) << ':';
+        OS << PLoc.getColumn() << ':';
       OS << ' ';
     }
     OS << "note: instantiated from:\n";