[PATCH] Fix BUILTINS_LOCATION with -fpreprocessed (PR preprocessor/41543)

Jakub Jelinek jakub@redhat.com
Mon Oct 12 19:14:00 GMT 2009


On Mon, Oct 12, 2009 at 12:23:43PM -0600, Tom Tromey wrote:
> >>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:
> 
> Jakub> I've kept this so that -E keeps printing:
> Jakub> # 1 "test.c"
> Jakub> # 1 "<built-in>"
> Jakub> # 1 "<command-line>"
> Jakub> # 1 "test.c"
> Jakub> as it always used to.  I guess at least some programs parsing -E output
> Jakub> might be confused if that <built-in> line goes away.
> 
> I see, thanks.
> 
> Do we know for sure that any code assigning a location to a builtin uses
> BUILTINS_LOCATION and not input_location?

Not for sure, though
1) several places which call functions that create builtins stuff are called
with
location_t saved_loc = input_location;
input_location = BUILTINS_LOCATION;
...
input_location = saved_loc;
around it.  See e.g. lang_dependent_init, or c_init_decl_processing
or cxx_init.  And most of the places use explicit BULTINS_LOCATION since
Aldy's changes anyway.
2) if they are not, it would be a -fpreprocessed only bug, both before the
patch and after it.  The patch wouldn't make it any worse I'd say.

> Jakub> Well, libcpp side doesn't do anything with UNKNOWN_LOCATION or
> Jakub> BUILTINS_LOCATION, all it does is reserve some number of lowest
> Jakub> numbered source_location values for caller's special uses.  So,
> Jakub> rather than putting those into libcpp libcpp perhaps should
> Jakub> define RESERVED_LOCATION_COUNT or something similar, and gcc
> Jakub> should assert that BUILTINS_LOCATION is smaller than that.
> 
> This sounds good to me.

Here it is:

2009-10-12  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.

	* 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.
	
--- gcc/input.h.jj	2008-09-05 12:56:31.000000000 +0200
+++ gcc/input.h	2009-10-12 11:08:36.000000000 +0200
@@ -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_ta
 #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 (())
 {
--- gcc/tree.c.jj	2009-10-05 10:07:14.000000000 +0200
+++ gcc/tree.c	2009-10-12 11:22:29.000000000 +0200
@@ -59,6 +59,7 @@ along with GCC; see the file COPYING3.  
 #include "timevar.h"
 #include "except.h"
 #include "debug.h"
+#include "intl.h"
 
 /* Tree code classes.  */
 
@@ -3939,9 +3940,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;
--- gcc/Makefile.in.jj	2009-10-07 09:24:54.000000000 +0200
+++ gcc/Makefile.in	2009-10-12 11:23:03.000000000 +0200
@@ -2243,7 +2243,7 @@ tree.o : tree.c $(CONFIG_H) $(SYSTEM_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
--- libcpp/include/line-map.h.jj	2009-07-20 20:42:19.000000000 +0200
+++ libcpp/include/line-map.h	2009-10-12 20:41:26.000000000 +0200
@@ -143,6 +143,11 @@ extern const struct line_map *linemap_ad
 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)
--- libcpp/line-map.c.jj	2009-05-04 16:46:48.000000000 +0200
+++ libcpp/line-map.c	2009-10-12 20:41:45.000000000 +0200
@@ -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;
 }
--- gcc/testsuite/gcc.dg/debug/dwarf2/pr41543.c.jj	2009-10-12 11:30:30.000000000 +0200
+++ gcc/testsuite/gcc.dg/debug/dwarf2/pr41543.c	2009-10-12 11:35:32.000000000 +0200
@@ -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 } } */


	Jakub



More information about the Gcc-patches mailing list