[cfe-commits] [PATCH] Suppress macro backtraces for notes

Richard Smith richard at metafoo.co.uk
Wed Dec 5 15:21:57 PST 2012


On Wed, Dec 5, 2012 at 8:57 AM, David Blaikie <dblaikie at gmail.com> wrote:

> On Wed, Dec 5, 2012 at 2:45 AM, Richard Smith <richard at metafoo.co.uk>
> wrote:
> > Based on a suggestion from Chandler, the attached patch suppresses
> > macro backtraces for notes.
> >
> > First, the "best" macro in the expansion chain is chosen (the lowest
> > ancestor of all the source locations provided for the diagnostic in
> > its caret, ranges and fixits). Then we walk up until we hit a line
> > which we also displayed in the macro backtrace for the primary
> > diagnostic. If we don't hit one, we just display the (distal)
> > expansion location for the note.
> >
> > For instance:
> >
> > #define FOO(x) x BAR;
> > #define BAR baz
> > #define QUUX FOO(int) FOO(double)
> > QUUX
> >
> > Previously:
> >
> > <stdin>:4:1: error: redefinition of 'baz' with a different type:
> 'double' vs
> >       'int'
> > QUUX
> > ^
> > <stdin>:3:23: note: expanded from macro 'QUUX'
> > #define QUUX FOO(int) FOO(double)
> >                       ^
> > <stdin>:1:18: note: expanded from macro 'FOO'
> > #define FOO(x) x BAR;
> >                  ^
> > <stdin>:2:13: note: expanded from macro 'BAR'
> > #define BAR baz
> >             ^
> > <stdin>:4:1: note: previous definition is here
> > QUUX
> > ^
> > <stdin>:3:14: note: expanded from macro 'QUUX'
> > #define QUUX FOO(int) FOO(double)
> >              ^
> > <stdin>:1:18: note: expanded from macro 'FOO'
> > #define FOO(x) x BAR;
> >                  ^
> > <stdin>:2:13: note: expanded from macro 'BAR'
> > #define BAR baz
> >             ^
> >
> > Now:
> >
> > <stdin>:4:1: error: redefinition of 'baz' with a different type:
> 'double' vs
> >       'int'
> > QUUX
> > ^
> > <stdin>:3:23: note: expanded from macro 'QUUX'
> > #define QUUX FOO(int) FOO(double)
> >                       ^
> > <stdin>:1:18: note: expanded from macro 'FOO'
> > #define FOO(x) x BAR;
> >                  ^
> > <stdin>:2:13: note: expanded from macro 'BAR'
> > #define BAR baz
> >             ^
> > <stdin>:3:14: note: previous definition is here
> > #define QUUX FOO(int) FOO(double)
> >              ^
> >
> > Thoughts?
>
> Should we note trace down through the FOO(int) macro instantiation? Or
> is the logic here that we've already traced through some FOO macro
> instantiation so we won't do another? Or more specific than that, only
> if the trace is the same?
>

It's more specific: only if it's the *same* macro expansion as one we've
already seen. (The idea is that you should be able to look at the line, see
it's the same as one you just saw a few lines above, and assume that you
got there in the same way.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121205/40608d64/attachment.html>


More information about the cfe-commits mailing list