This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: C FE and column numbers


This patch changes the C front end to use correct column numbers for
the decls it creates.

The key to this, for decls, is to make sure that input_location is set
properly before creating the decl node.

I chose to make a decl's location be the location of its identifier
token.  IMO this is the best choice.

However, there is one exception, which is that a function definition
is given the location of the opening brace of the function's body.
This is pre-existing code; I left it as-is on the theory that it gives
a better experience in the debugger.  This means that a function has
one location while parsing the "header" and then another once the body
is seen.  This is a bit odd (and resulted in the patch to the test
suite), but IMO is still clear and maintainable -- so I kept it.

Note that this patch does not handle expressions, or the C++ front
end, both of which require fixes for column numbers.

Bootstrapped and regtested with mapped locations on x86 FC-6.  Ok?

Tom

ChangeLog:
2007-10-30  Tom Tromey  <tromey@redhat.com>

	* c-decl.c (grokdeclarator): Set decl source locations.
	* c-parser.c (c_parser_enum_specifier): Set location.
	(c_parser_struct_or_union_specifier): Likewise.

testsuite/ChangeLog:
2007-10-30  Tom Tromey  <tromey@redhat.com>

	* gcc.dg/redecl-1.c: Update.
	* gcc.dg/pr20368-3.c: Update.
	* gcc.dg/inline-14.c: Update.
	* gcc.dg/builtins-30.c: Update.
	* gcc.dg/dremf-type-compat-4.c: Update.
	* gcc.dg/pr20368-2.c: Update.

Index: testsuite/gcc.dg/pr20368-2.c
===================================================================
--- testsuite/gcc.dg/pr20368-2.c	(revision 129492)
+++ testsuite/gcc.dg/pr20368-2.c	(working copy)
@@ -6,7 +6,7 @@
 extern __typeof (f) g; /* { dg-error "'f' undeclared here \\(not in a function\\)" } */
 
 int
-f (x)
-     float x; /* { dg-warning "no previous prototype for 'f'" } */
+f (x) /* { dg-warning "no previous prototype for 'f'" } */
+     float x;
 {
 }
Index: testsuite/gcc.dg/dremf-type-compat-4.c
===================================================================
--- testsuite/gcc.dg/dremf-type-compat-4.c	(revision 129492)
+++ testsuite/gcc.dg/dremf-type-compat-4.c	(working copy)
@@ -6,8 +6,8 @@
 /* { dg-options "" } */
 
 float
-dremf(x, y)
-     float x, y; /* { dg-warning "conflicting types for built-in function 'dremf'" } */
+dremf(x, y) /* { dg-warning "conflicting types for built-in function 'dremf'" } */
+     float x, y;
 {
   return x + y;
 }
Index: testsuite/gcc.dg/builtins-30.c
===================================================================
--- testsuite/gcc.dg/builtins-30.c	(revision 129492)
+++ testsuite/gcc.dg/builtins-30.c	(working copy)
@@ -6,22 +6,22 @@
 
 /* A built-in function may be overridden by an old-style definition
    specifying too few arguments... */
-double cos ()
-{  /* { dg-warning "shadows a built-in" } */
+double cos ()  /* { dg-warning "shadows a built-in" } */
+{
   /* { dg-warning "number of arguments doesn't match built-in prototype" "built-in" { target *-*-* } 10 } */
   return strtod ("nan", 0);
 }
 
 /* the right number, but the wrong type, arguments... */
-double sin (foo)
-     int foo UNUSED;  /* { dg-warning "shadows a built-in" } */
+double sin (foo)  /* { dg-warning "shadows a built-in" } */
+     int foo UNUSED;
 {  /* { dg-warning "argument 'foo' doesn't match built-in prototype" } */
   return strtod ("nan", 0);
 }
 
 /* or too many arguments.  */
-long double cosl (foo, bar)
-     const char *foo UNUSED;  /* { dg-warning "shadows a built-in" } */
+long double cosl (foo, bar)  /* { dg-warning "shadows a built-in" } */
+     const char *foo UNUSED;
      int bar UNUSED;
 {  /* { dg-warning "number of arguments doesn't match built-in prototype" } */
   /* { dg-warning "argument 'foo' doesn't match built-in prototype" "foo" { target *-*-* } 26 } */
Index: testsuite/gcc.dg/inline-14.c
===================================================================
--- testsuite/gcc.dg/inline-14.c	(revision 129492)
+++ testsuite/gcc.dg/inline-14.c	(working copy)
@@ -7,8 +7,8 @@
   return 1;
 }
 
-inline int func1 (void)
-{ /* { dg-error "redefinition" } */
+inline int func1 (void) /* { dg-error "redefinition" } */
+{
   return 1;
 }
 
@@ -17,7 +17,7 @@
   return 2;
 }
 
-inline int func2 (void)
-{ /* { dg-error "redefinition" } */
+inline int func2 (void) /* { dg-error "redefinition" } */
+{
   return 2;
 }
Index: testsuite/gcc.dg/pr20368-3.c
===================================================================
--- testsuite/gcc.dg/pr20368-3.c	(revision 129492)
+++ testsuite/gcc.dg/pr20368-3.c	(working copy)
@@ -6,7 +6,7 @@
 extern __typeof (f) g; /* { dg-error "'f' undeclared here \\(not in a function\\)" } */
 
 int
-f (x)
-     float x; /* { dg-warning "no previous declaration for 'f'" } */
+f (x) /* { dg-warning "no previous declaration for 'f'" } */
+     float x;
 {
 }
Index: testsuite/gcc.dg/redecl-1.c
===================================================================
--- testsuite/gcc.dg/redecl-1.c	(revision 129492)
+++ testsuite/gcc.dg/redecl-1.c	(working copy)
@@ -76,8 +76,8 @@
 /* Extern then static, both at file scope.  */
 
 extern int test6(int);		/* { dg-error "previous" "" } */
-static int test6(int x)			
-{ return x; }			/* { dg-error "follows non-static" } */
+static int test6(int x)		/* { dg-error "follows non-static" } */
+{ return x; }
 
 
 /* Extern then static, extern at previous function scope.  */
@@ -87,8 +87,8 @@
   extern int test7(int);	/* { dg-error "previous" "" } */
 }
 
-static int test7(int x)
-{ return x; }			/* { dg-error "follows non-static" } */
+static int test7(int x)		/* { dg-error "follows non-static" } */
+{ return x; }
 
 /* Implicit decl then static.  */
 
@@ -98,5 +98,5 @@
                                 /* { dg-warning "implicit" "implicit" { target *-*-* } 97 } */
 }
 
-static int test8(int x)
-{ return x; }			/* { dg-error "follows non-static" } */
+static int test8(int x)		/* { dg-error "follows non-static" } */
+{ return x; }
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 129492)
+++ c-decl.c	(working copy)
@@ -4645,6 +4645,7 @@
       if (type_quals)
 	type = c_build_qualified_type (type, type_quals);
       decl = build_decl (TYPE_DECL, declarator->u.id, type);
+      DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
       if (declspecs->explicit_signed_p)
 	C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
       if (declspecs->inline_p)
@@ -4740,6 +4741,7 @@
 	type_as_written = type;
 
 	decl = build_decl (PARM_DECL, declarator->u.id, type);
+	DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
 	if (size_varies)
 	  C_DECL_VARIABLE_SIZE (decl) = 1;
 
@@ -4779,6 +4781,7 @@
 	  }
 	type = c_build_qualified_type (type, type_quals);
 	decl = build_decl (FIELD_DECL, declarator->u.id, type);
+	DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
 	DECL_NONADDRESSABLE_P (decl) = bitfield;
 	if (bitfield && !declarator->u.id)
 	  TREE_NO_WARNING (decl) = 1;
@@ -4815,6 +4818,7 @@
 	  }
 
 	decl = build_decl (FUNCTION_DECL, declarator->u.id, type);
+	DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
 	decl = build_decl_attribute_variant (decl, decl_attr);
 
 	if (pedantic && type_quals && !DECL_IN_SYSTEM_HEADER (decl))
Index: c-parser.c
===================================================================
--- c-parser.c	(revision 129492)
+++ c-parser.c	(working copy)
@@ -1707,6 +1707,8 @@
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM));
   c_parser_consume_token (parser);
   attrs = c_parser_attributes (parser);
+  /* Set the location in case we create a decl now.  */
+  c_parser_set_source_position_from_token (c_parser_peek_token (parser));
   if (c_parser_next_token_is (parser, CPP_NAME))
     {
       ident = c_parser_peek_token (parser)->value;
@@ -1728,6 +1730,7 @@
 	  tree enum_value;
 	  tree enum_decl;
 	  bool seen_comma;
+	  c_token *token;
 	  if (c_parser_next_token_is_not (parser, CPP_NAME))
 	    {
 	      c_parser_error (parser, "expected identifier");
@@ -1735,7 +1738,10 @@
 	      values = error_mark_node;
 	      break;
 	    }
-	  enum_id = c_parser_peek_token (parser)->value;
+	  token = c_parser_peek_token (parser);
+	  enum_id = token->value;
+	  /* Set the location in case we create a decl now.  */
+	  c_parser_set_source_position_from_token (token);
 	  c_parser_consume_token (parser);
 	  if (c_parser_next_token_is (parser, CPP_EQ))
 	    {
@@ -1848,6 +1854,8 @@
     }
   c_parser_consume_token (parser);
   attrs = c_parser_attributes (parser);
+  /* Set the location in case we create a decl now.  */
+  c_parser_set_source_position_from_token (c_parser_peek_token (parser));
   if (c_parser_next_token_is (parser, CPP_NAME))
     {
       ident = c_parser_peek_token (parser)->value;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]