[cfe-commits] r90554 - /cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Chris Lattner sabre at nondot.org
Thu Dec 3 23:06:35 PST 2009


Author: lattner
Date: Fri Dec  4 01:06:35 2009
New Revision: 90554

URL: http://llvm.org/viewvc/llvm-project?rev=90554&view=rev
Log:
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


Modified:
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=90554&r1=90553&r2=90554&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Fri Dec  4 01:06:35 2009
@@ -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";





More information about the cfe-commits mailing list