From 96c169e15643ebffb7144837a54c760331d91c21 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Wed, 14 Oct 2009 12:04:22 +0200
Subject: [PATCH] re PR preprocessor/41543 (BUILTINS_LOCATION wrong with
 -fpreprocessed)

	PR preprocessor/41543
	* input.h (BUILTINS_LOCATION): Change to 1 from 2.
	Assert BUILTINS_LOCATION < RESERVED_LOCATION_COUNT.
	* tree.c: Include intl.h.
	(expand_location): Handle BUILTINS_LOCATION.
	* Makefile.in (tree.o): Depend on intl.h.

	* include/line-map.h (RESERVED_LOCATION_COUNT): Define.
	* line-map.c (linemap_init): Initialize highest_location and
	highest_line to RESERVED_LOCATION_COUNT-1 instead of 0.

	* gcc.dg/debug/dwarf2/pr41543.c: New test.

From-SVN: r152761
---
 gcc/ChangeLog                               |  7 +++++++
 gcc/Makefile.in                             |  2 +-
 gcc/input.h                                 |  9 +++++++--
 gcc/testsuite/ChangeLog                     |  3 +++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr41543.c | 14 ++++++++++++++
 gcc/tree.c                                  |  5 +++--
 libcpp/ChangeLog                            |  7 +++++++
 libcpp/include/line-map.h                   |  5 +++++
 libcpp/line-map.c                           |  4 ++--
 9 files changed, 49 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/pr41543.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 992f9b647c06..1e0069e4259b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
 2009-10-14  Jakub Jelinek  <jakub@redhat.com>
 
+	PR preprocessor/41543
+	* input.h (BUILTINS_LOCATION): Change to 1 from 2.
+	Assert BUILTINS_LOCATION < RESERVED_LOCATION_COUNT.
+	* tree.c: Include intl.h.
+	(expand_location): Handle BUILTINS_LOCATION.
+	* Makefile.in (tree.o): Depend on intl.h.
+
 	PR debug/41695
 	* dwarf2out.c (dwarf2out_var_location): Always clear
 	last_postcall_label when changing last_label.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 20d9db024375..34cba739a25e 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2243,7 +2243,7 @@ tree.o : tree.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
    langhooks.h $(REAL_H) gt-tree.h $(TREE_INLINE_H) tree-iterator.h \
    $(BASIC_BLOCK_H) $(TREE_FLOW_H) $(OBSTACK_H) pointer-set.h fixed-value.h \
    tree-pass.h $(LANGHOOKS_DEF_H) $(DIAGNOSTIC_H) $(CGRAPH_H) $(TIMEVAR_H) \
-   $(EXCEPT_H) debug.h
+   $(EXCEPT_H) debug.h intl.h
 tree-dump.o: tree-dump.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(TREE_H) langhooks.h $(TOPLEV_H) $(SPLAY_TREE_H) $(TREE_DUMP_H) \
    tree-iterator.h $(TREE_PASS_H) $(DIAGNOSTIC_H) $(REAL_H) fixed-value.h
diff --git a/gcc/input.h b/gcc/input.h
index 299f56c3ce64..7f00dc7cd0a7 100644
--- a/gcc/input.h
+++ b/gcc/input.h
@@ -1,6 +1,6 @@
 /* Declarations for variables relating to reading the source file.
    Used by parsers, lexical analyzers, and error message routines.
-   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007, 2008
+   Copyright (C) 1993, 1997, 1998, 2000, 2003, 2004, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -30,7 +30,12 @@ extern GTY(()) struct line_maps *line_table;
 #define UNKNOWN_LOCATION ((source_location) 0)
 
 /* The location for declarations in "<built-in>" */
-#define BUILTINS_LOCATION ((source_location) 2)
+#define BUILTINS_LOCATION ((source_location) 1)
+
+/* line-map.c reserves RESERVED_LOCATION_COUNT to the user.  Ensure
+   both UNKNOWN_LOCATION and BUILTINS_LOCATION fit into that.  */
+extern char builtins_location_check[(BUILTINS_LOCATION
+				     < RESERVED_LOCATION_COUNT) ? 1 : -1];
 
 typedef struct GTY (())
 {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c93c579c5c8a..3e8b069eaf2a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2009-10-14  Jakub Jelinek  <jakub@redhat.com>
 
+	PR preprocessor/41543
+	* gcc.dg/debug/dwarf2/pr41543.c: New test.
+
 	PR debug/41695
 	* gcc.dg/debug/dwarf2/pr41695.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr41543.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr41543.c
new file mode 100644
index 000000000000..02683960bdbf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr41543.c
@@ -0,0 +1,14 @@
+/* PR preprocessor/41543 */
+/* { dg-do compile } */
+/* { dg-options "-save-temps -g -O0 -dA -fno-merge-debug-strings" } */
+
+#include <stdarg.h>
+
+int
+foo (va_list ap)
+{
+  return va_arg (ap, int);
+}
+
+/* { dg-final { scan-assembler-not "DW_AT_decl_file\[^\\r\\n\]*\(pr41543\.i\)" } } */
+/* { dg-final { cleanup-saved-temps } } */
diff --git a/gcc/tree.c b/gcc/tree.c
index e0a5aea05e11..b58767a15908 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -59,6 +59,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "timevar.h"
 #include "except.h"
 #include "debug.h"
+#include "intl.h"
 
 /* Tree code classes.  */
 
@@ -3952,9 +3953,9 @@ expanded_location
 expand_location (source_location loc)
 {
   expanded_location xloc;
-  if (loc == 0)
+  if (loc <= BUILTINS_LOCATION)
     {
-      xloc.file = NULL;
+      xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>");
       xloc.line = 0;
       xloc.column = 0;
       xloc.sysp = 0;
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 9d9556ee0adc..3259c56f46e9 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2009-10-14  Jakub Jelinek  <jakub@redhat.com>
+
+	PR preprocessor/41543
+	* include/line-map.h (RESERVED_LOCATION_COUNT): Define.
+	* line-map.c (linemap_init): Initialize highest_location and
+	highest_line to RESERVED_LOCATION_COUNT-1 instead of 0.
+
 2009-10-09  Jason Merrill  <jason@redhat.com>
 
 	* charset.c (_cpp_valid_ucn): Update C++0x restrictions.
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 31ac8e5d4c3b..9e31a6ae3b97 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -143,6 +143,11 @@ extern const struct line_map *linemap_add
 extern const struct line_map *linemap_lookup
   (struct line_maps *, source_location);
 
+/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will
+   be reserved for libcpp user as special values, no token from libcpp
+   will contain any of those locations.  */
+#define RESERVED_LOCATION_COUNT	2
+
 /* Converts a map and a source_location to source line.  */
 #define SOURCE_LINE(MAP, LOC) \
   ((((LOC) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line)
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 553cc2ab605e..a82c4286f07b 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -38,8 +38,8 @@ linemap_init (struct line_maps *set)
   set->trace_includes = false;
   set->depth = 0;
   set->cache = 0;
-  set->highest_location = 0;
-  set->highest_line = 0;
+  set->highest_location = RESERVED_LOCATION_COUNT - 1;
+  set->highest_line = RESERVED_LOCATION_COUNT - 1;
   set->max_column_hint = 0;
   set->reallocator = 0;
 }
-- 
GitLab