Summary: | [4.5 Regression] Wrong error message location when compiling preprocessed code | ||
---|---|---|---|
Product: | gcc | Reporter: | Jörg Richter <joerg.richter> |
Component: | preprocessor | Assignee: | Jakub Jelinek <jakub> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | jakub, joel, tromey |
Priority: | P2 | ||
Version: | 4.5.2 | ||
Target Milestone: | 4.5.3 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | 4.5.2 | Last reconfirmed: | 2011-03-23 09:41:27 |
Attachments: | gcc46-pr48248.patch |
Description
Jörg Richter
2011-03-23 08:47:37 UTC
Confirmed.
> g++-4.5 -S foo.c -save-temps
foobar.h: In function ‘void func()’:
foobar.h:8:3: error: ‘aaa’ was not declared in this scope
and preprocessed source looks like
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "foo.c"
# 1 "foobar.h" 1
enum Foo
{
BAR
};
# 2 "foo.c" 2
void func()
{
(void)
# 6 "foobar.h"
BAR
;
aaa;
}
we miss to switch back to foo.c. 4.4 does not switch to foobar.h at all.
Can't reproduce this, neither with g++ 4.5, nor trunk. (In reply to comment #2) > Can't reproduce this, neither with g++ 4.5, nor trunk. Did you delete the empty lines? Ah, I can reproduce with those lines. Apparently caused by my PR41445 fix. To fix this, I think we should remember not just src_line, but also filename in print variable in c-ppoutput.c. And, either we should avoid calling do_line_change for avoid_paste resp. PREV_WHITE in scan_translation_unit if file is different, or maybe_print_line should do the if (src_line >= print.src_line && src_line < print.src_line + 8) optimization only if it is the same file. As PR41445 has been in already in 4.5 and nobody complained about e.g. # 1 "pr48248-2.C" # 1 "<built-in>" # 1 "<command-line>" # 1 "pr48248-2.C" # 1 "pr48248.h" 1 enum E { B }; # 2 "pr48248-2.C" 2 # 17 "pr48248-2.C" void foo () { (void) # 3 "pr48248.h" B # 20 "pr48248-2.C" ; a; } (where # 3 "pr48248.h" doesn't say that the header is being entered, just temporarily jumps to it), I'd probably prefer the latter choice, as it gives more correct locus info. Created attachment 23792 [details] gcc46-pr48248.patch Untested fix (the second alternative). Author: jakub Date: Tue Mar 29 20:25:27 2011 New Revision: 171693 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171693 Log: PR preprocessor/48248 * c-ppoutput.c (print): Add src_file field. (init_pp_output): Initialize it. (maybe_print_line): Don't optimize by adding up to 8 newlines if map->to_file and print.src_file are different file. (print_line): Update print.src_file. Modified: trunk/gcc/ChangeLog trunk/gcc/c-family/c-ppoutput.c Author: jakub Date: Tue Mar 29 20:30:06 2011 New Revision: 171697 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171697 Log: PR preprocessor/48248 * c-ppoutput.c (print): Add src_file field. (init_pp_output): Initialize it. (maybe_print_line): Don't optimize by adding up to 8 newlines if map->to_file and print.src_file are different file. (print_line): Update print.src_file. Modified: branches/gcc-4_6-branch/gcc/c-family/ChangeLog branches/gcc-4_6-branch/gcc/c-family/c-ppoutput.c Fixed for 4.6.1+ so far. Author: rguenth Date: Tue Apr 19 09:14:05 2011 New Revision: 172701 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172701 Log: 2011-04-18 Richard Guenther <rguenther@suse.de> PR preprocessor/48248 * c-ppoutput.c (maybe_print_line): Avoid changing -P behavior. Modified: branches/gcc-4_6-branch/gcc/c-family/ChangeLog branches/gcc-4_6-branch/gcc/c-family/c-ppoutput.c Author: rguenth Date: Tue Apr 19 09:19:33 2011 New Revision: 172703 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172703 Log: 2011-04-19 Richard Guenther <rguenther@suse.de> Backported from 4.6 branch 2011-03-29 Jakub Jelinek <jakub@redhat.com> PR preprocessor/48248 * c-ppoutput.c (print): Add src_file field. (init_pp_output): Initialize it. (maybe_print_line): Don't optimize by adding up to 8 newlines if map->to_file and print.src_file are different file. (print_line): Update print.src_file. 2011-04-18 Richard Guenther <rguenther@suse.de> PR preprocessor/48248 * c-ppoutput.c (maybe_print_line): Avoid changing -P behavior. Modified: branches/gcc-4_5-branch/gcc/ChangeLog branches/gcc-4_5-branch/gcc/c-ppoutput.c Fixed. Author: rguenth Date: Tue Apr 26 10:14:34 2011 New Revision: 172959 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172959 Log: 2011-04-26 Richard Guenther <rguenther@suse.de> PR preprocessor/48248 * c-ppoutput.c (maybe_print_line): Always optimize newlines for output size with -P. Modified: trunk/gcc/c-family/ChangeLog trunk/gcc/c-family/c-ppoutput.c |