https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108900
Bug ID: 108900
Summary: [libcpp] cpp gives wrong line number information
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: libin.dang at gmail dot com
Target Milestone: ---
Created attachment 54514
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54514&action=edit
test case
Reproduce:
$ /home/wrsadmin/works/gcc/b0/gcc/cpp -B /home/wrsadmin/works/gcc/b0/gcc main.c
-o main.i
$ tail main.i
header3 begins
header3 begins
# 1 "header2.h" 1
# 327614 "header3.h" 2
header3 ends
# 4 "header1.h" 2
# 1 "header4.h" 1
# 5 "header1.h" 2
header1 ends
# 2 "main.c" 2
$ cat -n header3.h | tail
327606 header3 begins
327607 header3 begins
327608 header3 begins
327609 header3 begins
327610 header3 begins
327611 header3 begins
327612 header3 begins
327613 header3 begins
327614 #include "header2.h"
327615 header3 ends
The line number information for `header3 ends' is wrong.
BTW, this issue is very sensitive to the input files, for example, if we add
another line `header3 begins' above the `#include "header2.h"' in header3.h, we
will get the correct result:
$ cat -n header3.h | tail
327607 header3 begins
327608 header3 begins
327609 header3 begins
327610 header3 begins
327611 header3 begins
327612 header3 begins
327613 header3 begins
327614 header3 begins
327615 #include "header2.h"
327616 header3 ends
$ tail main.i
header3 begins
header3 begins
# 1 "header2.h" 1
# 327616 "header3.h" 2
header3 ends
# 4 "header1.h" 2
# 1 "header4.h" 1
# 5 "header1.h" 2
header1 ends
# 2 "main.c" 2