diff options
author | Janus Weil <janus@gcc.gnu.org> | 2008-09-22 13:45:02 +0200 |
---|---|---|
committer | Janus Weil <janus@gcc.gnu.org> | 2008-09-22 13:45:02 +0200 |
commit | f613cea7fc41d8133a083ced6cc0a11b9312f110 (patch) | |
tree | 5ace57c212233d9f04bcb96b875d8137f2545d01 /gcc/fortran | |
parent | 22868cbf560231317a5c82348c08d396fa29f471 (diff) | |
download | gcc-f613cea7fc41d8133a083ced6cc0a11b9312f110.zip gcc-f613cea7fc41d8133a083ced6cc0a11b9312f110.tar.gz gcc-f613cea7fc41d8133a083ced6cc0a11b9312f110.tar.bz2 |
re PR fortran/37486 (alignment of data in COMMON blocks)
2008-09-22 Janus Weil <janus@gcc.gnu.org>
PR fortran/37486
* gfortran.h (gfc_option_t): New members flag_align_commons and
warn_align_commons.
* lang.opt: New options falign-commons and Walign-commons.
* invoke.texi: Documentation for new options.
* options.c (gfc_init_options): Initialize new options.
(gfc_handle_options): Handle new options.
* trans-common.c (translate_common): Implement new options.
(gfc_trans_common): Set correct locus.
2008-09-22 Janus Weil <janus@gcc.gnu.org>
PR fortran/37486
* gfortran.dg/common_align_1.f90: New.
* gfortran.dg/warn_align_commons.f90: New.
From-SVN: r140546
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 12 | ||||
-rw-r--r-- | gcc/fortran/gfortran.h | 2 | ||||
-rw-r--r-- | gcc/fortran/invoke.texi | 25 | ||||
-rw-r--r-- | gcc/fortran/lang.opt | 8 | ||||
-rw-r--r-- | gcc/fortran/options.c | 10 | ||||
-rw-r--r-- | gcc/fortran/trans-common.c | 42 |
6 files changed, 82 insertions, 17 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e362413..7744ba4 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,15 @@ +2008-09-22 Janus Weil <janus@gcc.gnu.org> + + PR fortran/37486 + * gfortran.h (gfc_option_t): New members flag_align_commons and + warn_align_commons. + * lang.opt: New options falign-commons and Walign-commons. + * invoke.texi: Documentation for new options. + * options.c (gfc_init_options): Initialize new options. + (gfc_handle_options): Handle new options. + * trans-common.c (translate_common): Implement new options. + (gfc_trans_common): Set correct locus. + 2008-09-21 Paul Thomas <pault@gcc.gnu.org> PR fortran/37583 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 444027b..fa3f865 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -1969,6 +1969,7 @@ typedef struct int warn_intrinsics_std; int warn_character_truncation; int warn_array_temp; + int warn_align_commons; int max_errors; int flag_all_intrinsics; @@ -2006,6 +2007,7 @@ typedef struct int flag_init_logical; int flag_init_character; char flag_init_character_value; + int flag_align_commons; int fpe; diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index b854ce4..2f6f4b0 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -138,7 +138,8 @@ and warnings}. -fsyntax-only -pedantic -pedantic-errors @gol -Wall -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation @gol -Wconversion -Wimplicit-interface -Wline-truncation -Wintrinsics-std @gol --Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter -Wintrinsics-shadow} +-Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter -Wintrinsics-shadow @gol +-Wno-align-commons} @item Debugging Options @xref{Debugging Options,,Options for debugging your program or GNU Fortran}. @@ -167,7 +168,7 @@ and warnings}. -fpack-derived -frepack-arrays -fshort-enums -fexternal-blas @gol -fblas-matmul-limit=@var{n} -frecursive -finit-local-zero @gol -finit-integer=@var{n} -finit-real=@var{<zero|inf|-inf|nan>} @gol --finit-logical=@var{<true|false>} -finit-character=@var{n}} +-finit-logical=@var{<true|false>} -finit-character=@var{n} -fno-align-commons} @end table @menu @@ -800,6 +801,14 @@ about unused dummy arguments, but about unused @code{PARAMETER} values. @option{-Wunused-parameter} is not included in @option{-Wall} but is implied by @option{-Wall -Wextra}. +@item -Walign-commons +@opindex @code{Walign-commons} +@cindex warnings, alignment of COMMON blocks +@cindex alignment of COMMON blocks +By default, @command{gfortran} warns about any occasion of variables being +padded for proper alignment inside a COMMON block. This warning can be turned +off via @option{-Wno-align-commons}. See also @option{-falign-commons}. + @item -Werror @opindex @code{Werror} @cindex warnings, to errors @@ -1275,6 +1284,18 @@ future releases). Note that the @option{-finit-real=nan} option initializes @code{REAL} and @code{COMPLEX} variables with a quiet NaN. + +@item -falign-commons +@opindex @code{falign-commons} +@cindex alignment of COMMON blocks +By default, @command{gfortran} enforces proper alignment of all variables in a +COMMON block by padding them as needed. On certain platforms this is mandatory, +on others it increases performance. If a COMMON block is not declared with +consistent data types everywhere, this padding can cause trouble, and +@option{-fno-align-commons } can be used to disable automatic alignment. The +same form of this option should be used for all files that share a COMMON block. +To avoid potential alignment issues in COMMON blocks, it is recommended to order +objects from largests to smallest. @end table @xref{Code Gen Options,,Options for Code Generation Conventions, diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 9321195..49055f3 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -72,6 +72,10 @@ Waliasing Fortran Warning Warn about possible aliasing of dummy arguments +Walign-commons +Fortran Warning +Warn about alignment of COMMON blocks + Wampersand Fortran Warning Warn about missing ampersand in continued character constants @@ -132,6 +136,10 @@ d Fortran Joined -d[DIMNU] Dump details about macro names and definitions during preprocessing +falign-commons +Fortran +Enable alignment of COMMON blocks + fall-intrinsics Fortran RejectNegative All intrinsics procedures are available regardless of selected standard diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 4ecb8f9..52174b3 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -78,6 +78,7 @@ gfc_init_options (unsigned int argc, const char **argv) gfc_option.warn_underflow = 1; gfc_option.warn_intrinsic_shadow = 0; gfc_option.warn_intrinsics_std = 0; + gfc_option.warn_align_commons = 1; gfc_option.max_errors = 25; gfc_option.flag_all_intrinsics = 0; @@ -117,6 +118,7 @@ gfc_init_options (unsigned int argc, const char **argv) gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF; gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF; gfc_option.flag_init_character_value = (char)0; + gfc_option.flag_align_commons = 1; gfc_option.fpe = 0; @@ -517,6 +519,10 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.warn_intrinsic_shadow = value; break; + case OPT_Walign_commons: + gfc_option.warn_align_commons = value; + break; + case OPT_fall_intrinsics: gfc_option.flag_all_intrinsics = 1; break; @@ -825,6 +831,10 @@ gfc_handle_option (size_t scode, const char *arg, int value) case OPT_frecursive: gfc_option.flag_recursive = 1; break; + + case OPT_falign_commons: + gfc_option.flag_align_commons = value; + break; } return result; diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c index 9e55792..92edd20 100644 --- a/gcc/fortran/trans-common.c +++ b/gcc/fortran/trans-common.c @@ -1059,7 +1059,9 @@ translate_common (gfc_common_head *common, gfc_symbol *var_list) bool saw_equiv; common_segment = NULL; + offset = 0; current_offset = 0; + align = 1; max_align = 1; saw_equiv = false; @@ -1100,16 +1102,27 @@ translate_common (gfc_common_head *common, gfc_symbol *var_list) "extension to COMMON '%s' at %L", sym->name, common->name, &common->where); - offset = align_segment (&align); + if (gfc_option.flag_align_commons) + offset = align_segment (&align); if (offset & (max_align - 1)) { /* The required offset conflicts with previous alignment requirements. Insert padding immediately before this segment. */ - gfc_warning ("Padding of %d bytes required before '%s' in " - "COMMON '%s' at %L", (int)offset, s->sym->name, - common->name, &common->where); + if (gfc_option.warn_align_commons) + { + if (strcmp (common->name, BLANK_COMMON_NAME)) + gfc_warning ("Padding of %d bytes required before '%s' in " + "COMMON '%s' at %L; reorder elements or use " + "-fno-align-commons", (int)offset, + s->sym->name, common->name, &common->where); + else + gfc_warning ("Padding of %d bytes required before '%s' in " + "COMMON at %L; reorder elements or use " + "-fno-align-commons", (int)offset, + s->sym->name, &common->where); + } } else { @@ -1138,10 +1151,16 @@ translate_common (gfc_common_head *common, gfc_symbol *var_list) return; } - if (common_segment->offset != 0) + if (common_segment->offset != 0 && gfc_option.warn_align_commons) { - gfc_warning ("COMMON '%s' at %L requires %d bytes of padding at start", - common->name, &common->where, (int)common_segment->offset); + if (strcmp (common->name, BLANK_COMMON_NAME)) + gfc_warning ("COMMON '%s' at %L requires %d bytes of padding at start; " + "reorder elements or use -fno-align-commons", + common->name, &common->where, (int)common_segment->offset); + else + gfc_warning ("COMMON at %L requires %d bytes of padding at start; " + "reorder elements or use -fno-align-commons", + &common->where, (int)common_segment->offset); } create_common (common, common_segment, saw_equiv); @@ -1225,14 +1244,7 @@ gfc_trans_common (gfc_namespace *ns) if (ns->blank_common.head != NULL) { c = gfc_get_common_head (); - - /* We've lost the real location, so use the location of the - enclosing procedure. */ - if (ns->proc_name != NULL) - c->where = ns->proc_name->declared_at; - else - c->where = ns->blank_common.head->common_head->where; - + c->where = ns->blank_common.head->common_head->where; strcpy (c->name, BLANK_COMMON_NAME); translate_common (c, ns->blank_common.head); } |