Commit f613cea7 by Janus Weil

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
parent 22868cbf
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
......
......@@ -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;
......
......@@ -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,
......
......@@ -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
......
......@@ -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;
......
......@@ -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);
}
......
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.
2008-09-22 Olivier Hainque <hainque@adacore.com>
* gnat.dg/volatile3.adb: New test.
......
! { dg-do run }
! { dg-options "-fno-align-commons" }
! PR fortran/37486
!
! Test for -fno-align-commons.
!
! Contributed by Tobias Burnus <burnus@gcc.gnu.org>.
subroutine one()
integer :: i
common i
if (i/=5) call abort()
end subroutine one
program test
integer :: i
real(8) :: r8
common i, r8
i = 5
call one()
end program test
! { dg-do compile }
! { dg-options "-Wno-align-commons" }
! PR fortran/37486
!
! Test for -Wno-align-commons.
!
! Contributed by Janus Weil <janus@gcc.gnu.org>.
implicit none
integer(kind=4) :: n
real(kind=8) :: p
common /foo/ n,p ! { dg-bogus "padding" }
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment