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] Don't ICE if the Fortran FE calls some stor-layout.c etc. function that emits warning, -Wpadded fixes (PR fortran/79886)


Hi!

The Fortran FE registers its own format decoder, overriding the default
one that handles what the middle-end can emit, e.g.
warning (OPT_Wpadded, "padding struct to align %q+D", field);
The C/C++ FEs are the only other ones that override the decoder, but they
do handle all the specs the generic decoder handles.

This patch chains the default decoder if the spec is not Fortran specific.

Another fix is to avoid -Wpadded warnings on every single TU when building
the IO artificial data structures.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-03-07  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/79886
	* tree-diagnostic.c (default_tree_printer): No longer static.
	* tree-diagnostic.h (default_tree_printer): New prototype.
fortran/
	* error.c (gfc_format_decoder): Rename plus argument to set_locus,
	remove ATTRIBUTE_UNUSED from all arguments, call default_tree_printer
	if not a Fortran specific spec.
	* trans-io.c: Include options.h.
	(gfc_build_st_parameter): Temporarily disable -Wpadded around layout
	of artificial IO data structures.
testsuite/
	* gfortran.dg/pr79886.f90: New test.

--- gcc/tree-diagnostic.c.jj	2017-01-01 12:45:35.000000000 +0100
+++ gcc/tree-diagnostic.c	2017-03-07 15:53:32.318241647 +0100
@@ -243,7 +243,7 @@ virt_loc_aware_diagnostic_finalizer (dia
 }
 
 /* Default tree printer.   Handles declarations only.  */
-static bool
+bool
 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
 		      int precision, bool wide, bool set_locus, bool hash)
 {
--- gcc/tree-diagnostic.h.jj	2017-01-01 12:45:37.000000000 +0100
+++ gcc/tree-diagnostic.h	2017-03-07 15:54:18.748626307 +0100
@@ -54,4 +54,7 @@ void virt_loc_aware_diagnostic_finalizer
 					  diagnostic_info *);
 
 void tree_diagnostics_defaults (diagnostic_context *context);
+bool default_tree_printer (pretty_printer *, text_info *, const char *,
+			   int, bool, bool, bool);
+
 #endif /* ! GCC_TREE_DIAGNOSTIC_H */
--- gcc/fortran/error.c.jj	2017-01-21 11:30:17.000000000 +0100
+++ gcc/fortran/error.c	2017-03-07 15:57:23.107159872 +0100
@@ -916,10 +916,8 @@ gfc_notify_std (int std, const char *gms
    %L  Takes locus argument
 */
 static bool
-gfc_format_decoder (pretty_printer *pp,
-		    text_info *text, const char *spec,
-		    int precision ATTRIBUTE_UNUSED, bool wide ATTRIBUTE_UNUSED,
-		    bool plus ATTRIBUTE_UNUSED, bool hash ATTRIBUTE_UNUSED)
+gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
+		    int precision, bool wide, bool set_locus, bool hash)
 {
   switch (*spec)
     {
@@ -946,7 +944,11 @@ gfc_format_decoder (pretty_printer *pp,
 	return true;
       }
     default:
-      return false;
+      /* Fall through info the middle-end decoder, as e.g. stor-layout.c
+	 etc. diagnostics can use the FE printer while the FE is still
+	 active.  */
+      return default_tree_printer (pp, text, spec, precision, wide,
+				   set_locus, hash);
     }
 }
 
--- gcc/fortran/trans-io.c.jj	2017-01-16 12:28:34.000000000 +0100
+++ gcc/fortran/trans-io.c	2017-03-07 16:06:03.818151237 +0100
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.
 #include "trans-array.h"
 #include "trans-types.h"
 #include "trans-const.h"
+#include "options.h"
 
 /* Members of the ioparm structure.  */
 
@@ -219,7 +220,12 @@ gfc_build_st_parameter (enum ioparam_typ
 	  gcc_unreachable ();
 	}
 
+  /* -Wpadded warnings on these artificially created structures are not
+     helpful; suppress them. */
+  int save_warn_padded = warn_padded;
+  warn_padded = 0;
   gfc_finish_type (t);
+  warn_padded = save_warn_padded;
   st_parameter[ptype].type = t;
 }
 
--- gcc/testsuite/gfortran.dg/pr79886.f90.jj	2017-03-07 16:09:29.880416741 +0100
+++ gcc/testsuite/gfortran.dg/pr79886.f90	2017-03-07 16:09:05.000000000 +0100
@@ -0,0 +1,17 @@
+! PR fortran/79886
+! { dg-do compile }
+! { dg-options "-Wpadded" }
+
+subroutine pr79886
+  type :: foo
+    integer (kind=1) :: a
+    integer (kind=8) :: b	! { dg-warning "padding struct to align" }
+    integer (kind=1) :: c
+    integer (kind=8) :: d	! { dg-warning "padding struct to align" }
+  end type
+  type (foo) :: f
+  f%a = 1
+  f%b = 2
+  f%c = 3
+  f%d = 4
+end subroutine

	Jakub


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