Which compiler pass prints a warning?

Martin Sebor msebor@gmail.com
Sun Sep 18 18:23:00 GMT 2016

On 09/17/2016 11:08 AM, Florian Weimer wrote:
> For warnings issued by the optimizers, is there a way to get the name
> of the pass which runs when the warning is generated?

I don't know of an easy or reliable way other than to grep the source
code for the text of warning (or its substrings when it's split across
multiple lines).  Short of that, I think it might be possible to come
close by looking at where in the output of -fdump-tree-all=/dev/stderr
the diagnostic appears and determining the pass from the context.
E.g., by

   gcc -O2 -S -Wall -fdump-tree-all=/dev/stdout z.c 2>&1 | less

and then searching the output for the warning and figuring out from
the contents of the dump around it what pass might have issued it.
Unfortunately, the dumps don't contain the name of their pass (I've
wished they did for other reasons) so this exercise isn't completely
straightforward either.


PS I think it would be useful to be able to more easily pinpoint
the source line responsible for emitting a diagnostic.  Others will
have a better idea of how feasible it might be to do but it seems
that having calls to error_at, warning_at, and others pass the
__FILE__ and __LINE__ of their caller to the diagnostic machinery
should make it possible to include this information in the text of
each diagnostic in response to some new option.

More information about the Gcc-help mailing list