make grokfield handle locations

Aldy Hernandez aldyh@redhat.com
Wed Aug 20 22:59:00 GMT 2008


On Wed, Aug 20, 2008 at 04:06:29PM -0400, Aldy Hernandez wrote:
> On Wed, Aug 20, 2008 at 06:33:32PM +0000, Joseph S. Myers wrote:
> > On Wed, 20 Aug 2008, Aldy Hernandez wrote:
> > 
> > > 	* c-tree.h (grokfield): New argument.
> > > 	* c-decl.c (grokfield): Handle new location argument.
> > > 	* c-parser.c (c_parser_struct_declaration): Pass location to
> > > 	grokfield.
> > >  testsuite/
> > > 	* gcc.dg/20011008-1.c: Test column.
> > > 	* gcc.dg/20080820.c: New.
> > 
> > The C front-end and testcase changes are OK.
> 
> [Tom, this is for you]
> 
> In testing I found that libcpp shows columns by default, so if the GCC
> driver didn't specifically set -fno-show-column, we will get column
> information by default on libcpp errors, but column-less errors in cc1.
> I assume this is the reason we passed -fno-show-column by default.
> 
> I won't even try to ask why this is so, and I'm sure breaking
> longstanding cpp behavior is probably not a good idea.
> 
> I have fixed the 4 affected testcases by passing -fno-show-column.  As
> an alternative we could make -fno-show-column the default for cpp.exp,
> but I would rather the current tests and/or future tests use the new
> { dg-error "COL:blahblah } functionality.
> 
> Tom, are you ok with the -fno-show-column changes to the 4 affected
> tests?

And now with the actual patch :)

	* c-tree.h (grokfield): New argument.
	* c-decl.c (grokfield): Handle new location argument.
	* c-parser.c (c_parser_struct_declaration): Pass location to
	grokfield.
 testsuite/
	* gcc.dg/20011008-1.c: Test column.
	* gcc.dg/20080820.c: New.
	* gcc.dg/fltconst-1.c: Pass -fno-show-column.
	* gcc.dg/cpp/pr28165.c: Same.
	* gcc.dg/cpp/paste15.c: Same.
	* gcc.dg/cpp/trad/assert2.c: Same.
	* lib/gcc.exp (gcc_target_compile): Remove -fno-show-column.
	* lib/gcc-dg.exp (process-message): Handle columns.

Index: testsuite/gcc.dg/fltconst-1.c
===================================================================
--- testsuite/gcc.dg/fltconst-1.c	(revision 139207)
+++ testsuite/gcc.dg/fltconst-1.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-std=gnu99" } */
+/* { dg-options "-std=gnu99 -fno-show-column" } */
 
 double a = 1.ld;	/* { dg-error "invalid suffix" } */
 double b = 1.fd;	/* { dg-error "invalid suffix" } */
Index: testsuite/gcc.dg/20011008-1.c
===================================================================
--- testsuite/gcc.dg/20011008-1.c	(revision 139207)
+++ testsuite/gcc.dg/20011008-1.c	(working copy)
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
-/* { dg-options "-O0" } */
+/* { dg-options "-O0 -fshow-column" } */
 
-struct { int; int q; } a; /* { dg-warning "does not declare anything" } */
+struct { int; int q; } a; /* { dg-warning "13:does not declare anything" } */
 struct { union {int x;}; int q; } b;
 struct { struct {int x;}; int q; } c;
 union { union {int x;}; int q; } d;
Index: testsuite/gcc.dg/cpp/pr28165.c
===================================================================
--- testsuite/gcc.dg/cpp/pr28165.c	(revision 139207)
+++ testsuite/gcc.dg/cpp/pr28165.c	(working copy)
@@ -2,5 +2,6 @@
 /* PR preprocessor/28165 */
 
 /* { dg-do preprocess } */
+/* { dg-options "-fno-show-column" } */
 #pragma GCC system_header   /* { dg-warning "system_header" "ignored" } */
 _Pragma ("GCC system_header")   /* { dg-warning "system_header" "ignored" } */
Index: testsuite/gcc.dg/cpp/paste15.c
===================================================================
--- testsuite/gcc.dg/cpp/paste15.c	(revision 139207)
+++ testsuite/gcc.dg/cpp/paste15.c	(working copy)
@@ -1,5 +1,6 @@
 /* PR preprocessor/20077 */
 /* { dg-do preprocess } */
+/* { dg-options "-fno-show-column" } */
 
 #define a   a ## ## /* { dg-error "end of a macro expansion" } */
 #define b() b ## ## /* { dg-error "end of a macro expansion" } */
Index: testsuite/gcc.dg/cpp/trad/assert2.c
===================================================================
--- testsuite/gcc.dg/cpp/trad/assert2.c	(revision 139207)
+++ testsuite/gcc.dg/cpp/trad/assert2.c	(working copy)
@@ -1,6 +1,6 @@
 /* Malformed assertion tests.  */
 /* { dg-do preprocess } */
-/* { dg-options "-Wno-deprecated" } */
+/* { dg-options "-Wno-deprecated -fno-show-column" } */
 
 #assert		/* { dg-error "without predicate" "assert w/o predicate" } */
 #assert %	/* { dg-error "an identifier" "assert punctuation" } */
Index: testsuite/gcc.dg/20080820.c
===================================================================
--- testsuite/gcc.dg/20080820.c	(revision 0)
+++ testsuite/gcc.dg/20080820.c	(revision 0)
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fshow-column -fms-extensions -pedantic" } */
+
+struct { struct a { int x; }; int bar; } hot; /* { dg-warning "29:ISO C doesn't support unnamed" } */
Index: testsuite/lib/gcc.exp
===================================================================
--- testsuite/lib/gcc.exp	(revision 139207)
+++ testsuite/lib/gcc.exp	(working copy)
@@ -150,7 +150,6 @@ proc gcc_target_compile { source dest ty
     if [target_info exists gcc,timeout] {
 	lappend options "timeout=[target_info gcc,timeout]"
     }
-    lappend options "additional_flags=-fno-show-column"
     lappend options "compiler=$GCC_UNDER_TEST"
     set options [dg-additional-files-options $options $source]
     return [target_compile $source $dest $type $options]
Index: testsuite/lib/gcc-dg.exp
===================================================================
--- testsuite/lib/gcc-dg.exp	(revision 139207)
+++ testsuite/lib/gcc-dg.exp	(working copy)
@@ -636,7 +636,18 @@ proc process-message { msgproc msgprefix
     # it match a single line.
     set newentry [lindex ${dg-messages} end]
     set expmsg [lindex $newentry 2]
-    set expmsg "$msgprefix\[^\n]*$expmsg"
+
+    # If we have a column...
+    if [regexp "^(\[0-9\]+):" $expmsg "" column] {
+	# Remove "COLUMN:"
+	regsub "^\[0-9\]+:" $expmsg "" expmsg
+
+	# Include the column in the search expression.
+	set expmsg "$column: $msgprefix\[^\n]*$expmsg"
+    } else {
+	set expmsg "$msgprefix\[^\n]*$expmsg"
+    }
+
     set newentry [lreplace $newentry 2 2 $expmsg]
     set dg-messages [lreplace ${dg-messages} end end $newentry]
     verbose "process-message:\n${dg-messages}" 2
Index: c-tree.h
===================================================================
--- c-tree.h	(revision 139207)
+++ c-tree.h	(working copy)
@@ -475,8 +475,8 @@ extern tree finish_enum (tree, tree, tre
 extern void finish_function (void);
 extern tree finish_struct (tree, tree, tree);
 extern struct c_arg_info *get_parm_info (bool);
-extern tree grokfield (struct c_declarator *, struct c_declspecs *,
-		       tree, tree *);
+extern tree grokfield (location_t, struct c_declarator *,
+		       struct c_declspecs *, tree, tree *);
 extern tree groktypename (struct c_type_name *);
 extern tree grokparm (const struct c_parm *);
 extern tree implicitly_declare (tree);
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 139207)
+++ c-decl.c	(working copy)
@@ -5342,12 +5342,15 @@ start_struct (enum tree_code code, tree 
    WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
    DECL_ATTRS is as for grokdeclarator.
 
+   LOC is the location of the structure component.
+
    This is done during the parsing of the struct declaration.
    The FIELD_DECL nodes are chained together and the lot of them
    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
 
 tree
-grokfield (struct c_declarator *declarator, struct c_declspecs *declspecs,
+grokfield (location_t loc,
+	   struct c_declarator *declarator, struct c_declspecs *declspecs,
 	   tree width, tree *decl_attrs)
 {
   tree value;
@@ -5393,10 +5396,11 @@ grokfield (struct c_declarator *declarat
 	}
       if (!ok)
 	{
-	  pedwarn (0, "declaration does not declare anything");
+	  pedwarn_at (loc, 0, "declaration does not declare anything");
 	  return NULL_TREE;
 	}
-      pedwarn (OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions");
+      pedwarn_at (loc, OPT_pedantic,
+		  "ISO C doesn%'t support unnamed structs/unions");
     }
 
   value = grokdeclarator (declarator, declspecs, FIELD, false,
Index: c-parser.c
===================================================================
--- c-parser.c	(revision 139207)
+++ c-parser.c	(working copy)
@@ -1966,7 +1966,9 @@ c_parser_struct_declaration (c_parser *p
 	     structs or unions (which is [a] useful and [b] supports
 	     MS P-SDK).  */
 	  tree attrs = NULL;
-	  ret = grokfield (build_id_declarator (NULL_TREE), specs,
+
+	  ret = grokfield (c_parser_peek_token (parser)->location,
+			   build_id_declarator (NULL_TREE), specs,
 			   NULL_TREE, &attrs);
 	  if (ret)
 	    decl_attributes (&ret, attrs, 0);
@@ -2009,7 +2011,8 @@ c_parser_struct_declaration (c_parser *p
 	    }
 	  if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
 	    postfix_attrs = c_parser_attributes (parser);
-	  d = grokfield (declarator, specs, width, &all_prefix_attrs);
+	  d = grokfield (c_parser_peek_token (parser)->location,
+			 declarator, specs, width, &all_prefix_attrs);
 	  decl_attributes (&d, chainon (postfix_attrs,
 					all_prefix_attrs), 0);
 	  TREE_CHAIN (d) = decls;



More information about the Gcc-patches mailing list