https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69126
--- Comment #5 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
As far as I can tell:
* _Pragma is handled by _cpp_do__Pragma which injects pragma tokens into the
token stream
* the resulting "ignore" pragmas are handled by
gcc/c-family/c-pragma.c:handle_pragma_diagnostic which calls:
* control_warning_option, which calls
* diagnostic_classify_diagnostic, which leads to an element being pushed
onto context->classification_history with location as the location of the
token.
When handling the warning/warning_at, diagnostic_report_diagnostic has this
logic:
695 /* This tests for #pragma diagnostic changes. */
696 if (context->n_classification_history > 0)
697 {
698 int i;
699 /* FIXME: Stupid search. Optimize later. */
700 for (i = context->n_classification_history - 1; i >= 0; i --)
701 {
702 if (linemap_location_before_p
703 (line_table,
704 context->classification_history[i].location,
705 location))
Note the call to linemap_location_before_p, which calls
linemap_compare_locations.
That said, the location of the token from _Pragma looks wrong; note the
underlines here:
Breakpoint 2, handle_pragma_diagnostic (dummy=<optimized out>) at
../../src/gcc/c-family/c-pragma.c:760
760 kind = DK_IGNORED;
(gdb) call inform (loc, "1st ignore")
/tmp/test.cc: In function ‘int f()’:
/tmp/test.cc:4:16: note: 1st ignore
_Pragma("GCC diagnostic ignored \"-Wunused-variable\"")
^~~~~~~
(gdb) cont
Continuing.
Breakpoint 2, handle_pragma_diagnostic (dummy=<optimized out>) at
../../src/gcc/c-family/c-pragma.c:760
760 kind = DK_IGNORED;
(gdb) call inform (loc, "2nd ignore")
/tmp/test.cc: In function ‘int g()’:
/tmp/test.cc:17:16: note: 2nd ignore
MACRO;
^