It seems that long comment blocks can throw off gcc's notion of the source line number. Here is a sample test case (also attached in case the line breaks get messed up pasting in): /* This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. This is a really long comment. */ #warning test warning #include <stdio.h> int main(int argc, char *argv) { printf("This is line %d\n", __LINE__); }
Confirmed. This has been broken since at least "gcc version 3.5.0 20040909 (experimental)".
This broke between 20040201 and 20040301.
There were quiet a number of cpp patches during that time.
Created attachment 8685 [details] Tentative patch.
Subject: Bug 20907 CVSROOT: /cvs/gcc Module name: gcc Changes by: bothner@gcc.gnu.org 2005-04-21 17:08:29 Modified files: libcpp : line-map.c ChangeLog Log message: PR preprocessor/20907 * line-map.c (linemap_line_start): Fix bug when we need to increse column_bits but can re-use the current line_map. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/line-map.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/ChangeLog.diff?cvsroot=gcc&r1=1.67&r2=1.68
Patch checked into mainline; not yet into 4.0 branch.
Subject: Re: [4.0/4.1 Regression] long comments throw off line numbers Would it be possible for you to add one test case also ? Thanks, - Devang
Subject: Bug 20907 CVSROOT: /cvs/gcc Module name: gcc Branch: apple-local-200502-branch Changes by: dpatel@gcc.gnu.org 2005-04-21 18:40:08 Modified files: libcpp : line-map.c ChangeLog.apple-ppc gcc/testsuite : ChangeLog.apple-ppc Added files: gcc/testsuite/gcc.apple: very-long-comment.c Log message: Radar 4058553 Backport from FSF Mainline. 2005-04-19 Per Bothner <per@bothner.com> PR preprocessor/20907 * line-map.c (linemap_line_start): Fix bug when we need to increse column_bits but can re-use the current line_map. * gcc.apple/very-long-comment.c: New. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/line-map.c.diff?cvsroot=gcc&only_with_tag=apple-local-200502-branch&r1=1.1&r2=1.1.52.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/ChangeLog.apple-ppc.diff?cvsroot=gcc&only_with_tag=apple-local-200502-branch&r1=1.1.4.4&r2=1.1.4.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.apple/very-long-comment.c.diff?cvsroot=gcc&only_with_tag=apple-local-200502-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.apple-ppc.diff?cvsroot=gcc&only_with_tag=apple-local-200502-branch&r1=1.1.4.22&r2=1.1.4.23
Subject: Bug 20907 CVSROOT: /cvs/gcc Module name: gcc Changes by: bothner@gcc.gnu.org 2005-04-24 20:05:30 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg/cpp: very-long-comment.c Log message: PR preprocessor/20907 * gcc.dg/cpp/very-long-comment.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/cpp/very-long-comment.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5390&r2=1.5391
Subject: Bug 20907 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: bothner@gcc.gnu.org 2005-04-24 20:32:32 Modified files: libcpp : line-map.c ChangeLog Log message: PR preprocessor/20907 * line-map.c (linemap_line_start): Fix bug when we need to increse column_bits but can re-use the current line_map. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/line-map.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1&r2=1.1.54.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libcpp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.56.2.5&r2=1.56.2.6
Subject: Bug 20907 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: bothner@gcc.gnu.org 2005-04-24 20:37:39 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg/cpp: very-long-comment.c Log message: PR preprocessor/20907 * gcc.dg/cpp/very-long-comment.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/cpp/very-long-comment.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.136&r2=1.5084.2.137
Fixed.