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

David Blaikie dblaikie at gmail.com
Wed Dec 5 08:57:25 PST 2012


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?
(eg: if the FOO macro defined two variables and it was the first
definition in one instantiation that conflicted with the second
definition in the other, so it's not exactly the same backtrace)



More information about the cfe-commits mailing list