PR preprocessor/60723 - missing system-ness marks for macro tokens
commit747e04f26ac3fb775bfc9af61e9170b9461b6cfc
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 1 Jul 2014 09:17:14 +0000 (1 09:17 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 1 Jul 2014 09:17:14 +0000 (1 09:17 +0000)
tree1fde075dec58b3c71e072098b75141c6030eb699
parent1207866ef97bfc119433ed86b9795debb947144b
PR preprocessor/60723 - missing system-ness marks for macro tokens

When a system macro is expanded in a non-system file during
out-of-line preprocessing, it can happen that the preprocessor forgets
to emit line markers to express the system-ness status of tokens that
come after the expansion of the macro.

That can lead to situations where the entire non-system file can be
considered as being a system file and thus have its warnings be
discarded during the compilation of the resulting preprocessed file.

My understanding is that this is due to the preprocessor not
systematically detecting (and reporting) the change in system-ness of
tokens.

And this is what this patch does.  Each time the system-ness of a
given token is different from the previous token that was emitted by
the preprocessor, it emits a line marker for the sole purpose of
marking the new system-ness of the subsequent tokens to come.

Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.

gcc/c-family/ChangeLog:
* c-ppoutput.c (struct print::prev_was_system_token): New data
member.
(init_pp_output): Initialize it.
(maybe_print_line_1, maybe_print_line, print_line_1, print_line)
(do_line_change): Return a flag saying if a line marker was
emitted or not.
(scan_translation_unit): Detect if the system-ness of the token we
are about to emit is different from the one of the previously
emitted token.  If so, emit a line marker.  Avoid emitting
useless adjacent line markers.
(scan_translation_unit_directives_only): Adjust.

gcc/testsuite/ChangeLog:
* gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@212194 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/c-family/ChangeLog
gcc/c-family/c-ppoutput.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/syshdr4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/syshdr4.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/syshdr5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/syshdr5.h [new file with mode: 0644]