From 00b0c19b4bbfa483925a177ed3e6ce2e1f42444b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= <manu@gcc.gnu.org>
Date: Wed, 13 May 2009 23:17:55 +0000
Subject: [PATCH] re PR preprocessor/36674 (#include location is offset by one
 row in errors from preprocessed files)

2009-05-14  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR cpp/36674
libcpp/
	* directives (do_linemarker): Compensate for the increment in
	location that occurs when we reach the end of line.
	* files (_cpp_stack_include): Mention _cpp_find_file in the
	comment.
testsuite/
	* gcc.dg/cpp/pr36674.i: New.

From-SVN: r147504
---
 gcc/testsuite/ChangeLog            |  5 +++++
 gcc/testsuite/gcc.dg/cpp/pr36674.i | 12 ++++++++++++
 libcpp/ChangeLog                   |  8 ++++++++
 libcpp/directives.c                |  8 ++++++++
 libcpp/files.c                     | 15 ++++++++-------
 5 files changed, 41 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/cpp/pr36674.i

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 928c7f63a823..f9580aa46a66 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-05-14  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+	PR cpp/36674
+	* gcc.dg/cpp/pr36674.i: New.
+
 2009-05-14  Ben Elliston  <bje@au.ibm.com>
 	 
 	PR middle-end/40035
diff --git a/gcc/testsuite/gcc.dg/cpp/pr36674.i b/gcc/testsuite/gcc.dg/cpp/pr36674.i
new file mode 100644
index 000000000000..9362d5a40808
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/pr36674.i
@@ -0,0 +1,12 @@
+/* PR cpp/36674  #include location is offset by one row in errors from preprocessed files */
+/* { dg-do compile } */
+/* { dg-options "-fshow-column" } */
+# 1 "gcc/testsuite/gcc.dg/pr36674.c"
+# 1 "<built-in>"
+# 1 "<command-line>"
+# 1 "gcc/testsuite/gcc.dg/pr36674.c"
+# 1 "gcc/testsuite/gcc.dg/pr36674.h" 1
+not_declared_yet();
+# 1 "gcc/testsuite/gcc.dg/pr36674.c" 2
+/* { dg-message "file included from \[^\n\]*pr36674.c:1:" "correct include line" { target *-*-* } 0 } */
+/* { dg-message "pr36674.h:1:1: warning: data definition has no type or storage class" "correct warning" { target *-*-* } 0 } */
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 4e21b5811215..36a2fbc1c565 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,11 @@
+2009-05-14  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+	PR cpp/36674
+	* directives (do_linemarker): Compensate for the increment in
+	location that occurs when we reach the end of line.
+	* files (_cpp_stack_include): Mention _cpp_find_file in the
+	comment.
+
 2009-05-10  Joseph Myers  <joseph@codesourcery.com>
 
 	* include/cpplib.h (enum cpp_token_fld_kind): Add
diff --git a/libcpp/directives.c b/libcpp/directives.c
index e71efb2bd94e..74644ff6c776 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -1004,6 +1004,14 @@ do_linemarker (cpp_reader *pfile)
     }
 
   skip_rest_of_line (pfile);
+
+  /* Compensate for the increment in linemap_add that occurs in
+     _cpp_do_file_change.  We're currently at the start of the line
+     *following* the #line directive.  A separate source_location for this
+     location makes no sense (until we do the LC_LEAVE), and
+     complicates LAST_SOURCE_LINE_LOCATION.  */
+  pfile->line_table->highest_location--;
+
   _cpp_do_file_change (pfile, reason, new_file, new_lineno, new_sysp);
 }
 
diff --git a/libcpp/files.c b/libcpp/files.c
index 06ccd0fd6953..c8c19021f565 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -912,13 +912,14 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
 
   file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
 
-  /* Compensate for the increment in linemap_add.  In the case of a
-     normal #include, we're currently at the start of the line
-     *following* the #include.  A separate source_location for this
-     location makes no sense (until we do the LC_LEAVE), and
-     complicates LAST_SOURCE_LINE_LOCATION.  This does not apply if we
-     found a PCH file (in which case linemap_add is not called) or we
-     were included from the command-line.  */
+  /* Compensate for the increment in linemap_add that occurs in
+     _cpp_stack_file.  In the case of a normal #include, we're
+     currently at the start of the line *following* the #include.  A
+     separate source_location for this location makes no sense (until
+     we do the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION.
+     This does not apply if we found a PCH file (in which case
+     linemap_add is not called) or we were included from the
+     command-line.  */
   if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE)
     pfile->line_table->highest_location--;
 
-- 
GitLab