[cfe-commits] r64761 - /cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp

Cédric Venet cedric.venet at laposte.net
Tue Feb 17 02:20:27 PST 2009


Chris Lattner a écrit :
> Author: lattner
> Date: Tue Feb 17 02:44:50 2009
> New Revision: 64761
>
> URL: http://llvm.org/viewvc/llvm-project?rev=64761&view=rev
> Log:
> As an experimental hack, emit "instantiated from" information in
> diagnostics.  I'm not sure I want to keep this, but hey, it's easy
> and could be useful or something, even if guarded by a 
> -fshow-me-tons-of-details option.  A silly example is:
>   

It would definitively be useful in some case. For example, I wrote some 
Boost PP (preprocessor programming) code some time ago, and it was 
nearly impossible to understand what, when and why an instantiation went 
wrong. This would help.

> #define A B
> #define C A
> #define D C
>
> int y = D;
>
> We now emit:
>
> t.c:11:9: error: use of undeclared identifier 'B'
> int y = D;
>         ^
> t.c:9:11: note: instantiated from:
> #define D C
>           ^
> t.c:8:11: note: instantiated from:
> #define C A
>           ^
> t.c:7:11: note: instantiated from:
> #define A B
>           ^
>
> A more useful example is from tgmath:
>
> t.c:4:9: error: no matching function for call to '__tg_acos'
>  return acos(x);
>         ^~~~~~~
> /Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:51:17: note: instantiated from:
> #define acos(x) __tg_acos(x)
>                 ^
> .. candidate set follows ...
>
> This does not yet print ranges in instantiation info, (e.g. highlighting the
> range "__tg_acos(x)" in the last example), but that could be added if we 
> decide this is a good idea :).
>
> Thoughts and bug reports welcome!
>
>
> Modified:
>     cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp
>
> Modified: cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp?rev=64761&r1=64760&r2=64761&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp (original)
> +++ cfe/trunk/lib/Driver/TextDiagnosticPrinter.cpp Tue Feb 17 02:44:50 2009
> @@ -104,9 +104,25 @@
>  void TextDiagnosticPrinter::EmitCaretDiagnostic(const DiagnosticInfo &Info,
>                                                  SourceLocation Loc,
>                                                  SourceManager &SM) {
> +  assert(!Loc.isInvalid() && "must have a valid source location here");
> +  
>    // We always emit diagnostics about the instantiation points, not the spelling
>    // points.  This more closely correlates to what the user writes.
> -  Loc = SM.getInstantiationLoc(Loc);
> +  if (!Loc.isFileID()) {
> +    SourceLocation OneLevelUp;
> +    OneLevelUp = SM.getImmediateInstantiationRange(Loc).first;
> +    
> +    EmitCaretDiagnostic(Info, OneLevelUp, SM);
> +    
> +    Loc = SM.getInstantiationLoc(SM.getImmediateSpellingLoc(Loc));
> +    
> +    // Emit the file/line/column that this expansion came from.
> +    OS << SM.getBufferName(Loc) << ':' << SM.getInstantiationLineNumber(Loc)
> +       << ':';
> +    if (ShowColumn)
> +      OS << SM.getInstantiationColumnNumber(Loc) << ':';
> +    OS << " note: instantiated from:\n";
> +  }
>    
>    // Decompose the location into a FID/Offset pair.
>    std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>   




More information about the cfe-commits mailing list