Commit f4347334 by Zydrunas Gimbutas Committed by Steven G. Kargl

re PR fortran/48426 ([patch] Quad precision promotion)

2012-01-16  Zydrunas Gimbutas  <gimbutas@cims.nyu.edu>
	    Andreas Kloeckner  <kloeckner@cims.nyu.edu>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/48426
	* gfortran.h (gfc_option_t): Add members flag_*_kind to store kind.
	* lang.opt: Add options -freal-4-real-8, -freal-4-real-10,
	-freal-4-real-16, -freal-8-real-4, -freal-8-real-10, -freal-8-real-16
	and -finteger-4-integer-8. User-desired type conversion information.
	* decl.c (gfc_match_old_kind_spec,kind_expr): Type conversions
	in declaration parsing.
	* trans-types.c (gfc_init_kinds): User-specified type conversion
	checked for current backend.
	* primary.c (match_integer_constant,match_real_constant): Implement
	type conversion in constant parsing.
	* options.c (gfc_init_options,gfc_handle_option): Translate input
	options to flags in internal options data structure.
	* invoke.texi: Document new options.  Re-order options in Options
	summary section.

From-SVN: r183217
parent 866e6d1b
/* Declaration statement matcher
Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
Contributed by Andy Vaught
......@@ -1572,7 +1572,8 @@ build_struct (const char *name, gfc_charlen *cl, gfc_expr **init,
/* Should this ever get more complicated, combine with similar section
in add_init_expr_to_sym into a separate function. */
if (c->ts.type == BT_CHARACTER && !c->attr.pointer && c->initializer && c->ts.u.cl
if (c->ts.type == BT_CHARACTER && !c->attr.pointer && c->initializer
&& c->ts.u.cl
&& c->ts.u.cl->length && c->ts.u.cl->length->expr_type == EXPR_CONSTANT)
{
int len;
......@@ -2101,6 +2102,33 @@ gfc_match_old_kind_spec (gfc_typespec *ts)
return MATCH_ERROR;
}
ts->kind /= 2;
}
if (ts->type == BT_INTEGER && ts->kind == 4 && gfc_option.flag_integer4_kind == 8)
ts->kind = 8;
if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
{
if (ts->kind == 4)
{
if (gfc_option.flag_real4_kind == 8)
ts->kind = 8;
if (gfc_option.flag_real4_kind == 10)
ts->kind = 10;
if (gfc_option.flag_real4_kind == 16)
ts->kind = 16;
}
if (ts->kind == 8)
{
if (gfc_option.flag_real8_kind == 4)
ts->kind = 4;
if (gfc_option.flag_real8_kind == 10)
ts->kind = 10;
if (gfc_option.flag_real8_kind == 16)
ts->kind = 16;
}
}
if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
......@@ -2246,7 +2274,33 @@ kind_expr:
if(m == MATCH_ERROR)
gfc_current_locus = where;
if (ts->type == BT_INTEGER && ts->kind == 4 && gfc_option.flag_integer4_kind == 8)
ts->kind = 8;
if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
{
if (ts->kind == 4)
{
if (gfc_option.flag_real4_kind == 8)
ts->kind = 8;
if (gfc_option.flag_real4_kind == 10)
ts->kind = 10;
if (gfc_option.flag_real4_kind == 16)
ts->kind = 16;
}
if (ts->kind == 8)
{
if (gfc_option.flag_real8_kind == 4)
ts->kind = 4;
if (gfc_option.flag_real8_kind == 10)
ts->kind = 10;
if (gfc_option.flag_real8_kind == 16)
ts->kind = 16;
}
}
/* Return what we know from the test(s). */
return m;
......
......@@ -2221,6 +2221,9 @@ typedef struct
int flag_default_double;
int flag_default_integer;
int flag_default_real;
int flag_integer4_kind;
int flag_real4_kind;
int flag_real8_kind;
int flag_dollar_ok;
int flag_underscoring;
int flag_second_underscore;
......
@c Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
@c Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
@c Free Software Foundation, Inc.
@c This is part of the GNU Fortran manual.
@c For copying conditions, see the file gfortran.texi.
......@@ -66,7 +66,8 @@ GNU Fortran.
@c man begin DESCRIPTION
The @command{gfortran} command supports all the options supported by the
@command{gcc} command. Only options specific to GNU Fortran are documented here.
@command{gcc} command. Only options specific to GNU Fortran are documented
here.
@xref{Invoking GCC,,GCC Command Options,gcc,Using the GNU Compiler
Collection (GCC)}, for information
......@@ -115,37 +116,46 @@ by type. Explanations are in the following sections.
@table @emph
@item Fortran Language Options
@xref{Fortran Dialect Options,,Options controlling Fortran dialect}.
@gccoptlist{-fall-intrinsics -ffree-form -fno-fixed-form @gol
-fdollar-ok -fimplicit-none -fmax-identifier-length @gol
-std=@var{std} -fd-lines-as-code -fd-lines-as-comments @gol
-ffixed-line-length-@var{n} -ffixed-line-length-none @gol
-ffree-line-length-@var{n} -ffree-line-length-none @gol
-fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 @gol
-fcray-pointer -fopenmp -fno-range-check -fbackslash -fmodule-private}
@gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol
-fd-lines-as-comments -fdefault-double-8 -fdefault-integer-8 @gol
-fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol
-ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol
-ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol
-fmax-identifier-length -fmodule-private -fno-fixed-form -fno-range-check @gol
-fopenmp -freal-4-real-10 -freal-4-real-16 -freal-4-real-8 @gol
-freal-8-real-10 -freal-8-real-16 -freal-8-real-4 -std=@var{std}
}
@item Preprocessing Options
@xref{Preprocessing Options,,Enable and customize preprocessing}.
@gccoptlist{-cpp -dD -dI -dM -dN -dU -fworking-directory @gol
-imultilib @var{dir} -iprefix @var{file} -isysroot @var{dir} @gol
-iquote -isystem @var{dir} -nocpp -nostdinc -undef @gol
-A@var{question}=@var{answer} -A-@var{question}@r{[}=@var{answer}@r{]} @gol
-C -CC -D@var{macro}@r{[}=@var{defn}@r{]} -U@var{macro} -H -P}
@gccoptlist{-A-@var{question}@r{[}=@var{answer}@r{]}
-A@var{question}=@var{answer} -C -CC -D@var{macro}@r{[}=@var{defn}@r{]}
-H -P @gol
-U@var{macro} -cpp -dD -dI -dM -dN -dU -fworking-directory
-imultilib @var{dir} @gol
-iprefix @var{file} -iquote -isysroot @var{dir} -isystem @var{dir} -nocpp
-nostdinc @gol
-undef
}
@item Error and Warning Options
@xref{Error and Warning Options,,Options to request or suppress errors
and warnings}.
@gccoptlist{-fmax-errors=@var{n}
-fsyntax-only -pedantic -pedantic-errors -Wall @gol
-Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation @gol
-Wconversion -Wimplicit-interface -Wimplicit-procedure -Wline-truncation @gol
-Wintrinsics-std -Wreal-q-constant -Wsurprising -Wno-tabs -Wunderflow @gol
-Wunused-parameter -Wintrinsic-shadow -Wno-align-commons @gol
-Wfunction-elimination}
@gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds
-Wcharacter-truncation @gol
-Wconversion -Wfunction-elimination -Wimplicit-interface @gol
-Wimplicit-procedure -Wintrinsic-shadow -Wintrinsics-std @gol
-Wline-truncation -Wno-align-commons -Wno-tabs -Wreal-q-constant @gol
-Wsurprising -Wunderflow -Wunused-parameter -fmax-errors=@var{n}
-fsyntax-only @gol
-pedantic -pedantic-errors
}
@item Debugging Options
@xref{Debugging Options,,Options for debugging your program or GNU Fortran}.
@gccoptlist{-fdump-fortran-original -fdump-fortran-optimized @gol
-ffpe-trap=@var{list} -fbacktrace -fdump-parse-tree}
@gccoptlist{-fbacktrace -fdump-fortran-optimized -fdump-fortran-original @gol
-fdump-parse-tree -ffpe-trap=@var{list}
}
@item Directory Options
@xref{Directory Options,,Options for directory search}.
......@@ -157,39 +167,29 @@ and warnings}.
@item Runtime Options
@xref{Runtime Options,,Options for influencing runtime behavior}.
@gccoptlist{-fconvert=@var{conversion} -fno-range-check
-frecord-marker=@var{length} @gol -fmax-subrecord-length=@var{length}
-fsign-zero}
@gccoptlist{-fconvert=@var{conversion} -fmax-subrecord-length=@var{length}
-fno-range-check @gol
-frecord-marker=@var{length} -fsign-zero
}
@item Code Generation Options
@xref{Code Gen Options,,Options for code generation conventions}.
@gccoptlist{-fno-automatic -ff2c -fno-underscoring @gol
-fno-whole-file -fsecond-underscore @gol
-fbounds-check -fcheck-array-temporaries -fmax-array-constructor =@var{n} @gol
@gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol
-fbounds-check -fcheck-array-temporaries @gol
-fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>} @gol
-fcoarray=@var{<none|single|lib>} -fmax-stack-var-size=@var{n} @gol
-fstack-arrays @gol
-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|snan>} @gol
-finit-logical=@var{<true|false>} -finit-character=@var{n} @gol
-fno-align-commons -fno-protect-parens -frealloc-lhs @gol
-faggressive-function-elimination -ffrontend-optimize}
-fcoarray=@var{<none|single|lib>} -fexternal-blas -ff2c
-ffrontend-optimize @gol
-finit-character=@var{n} -finit-integer=@var{n} -finit-local-zero @gol
-finit-logical=@var{<true|false>}
-finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
-fmax-array-constructor=@var{n} -fmax-stack-var-size=@var{n}
-fno-align-commons @gol
-fno-automatic -fno-protect-parens -fno-underscoring -fno-whole-file @gol
-fsecond-underscore -fpack-derived -frealloc-lhs -frecursive @gol
-frepack-arrays -fshort-enums -fstack-arrays
}
@end table
@menu
* Fortran Dialect Options:: Controlling the variant of Fortran language
compiled.
* Preprocessing Options:: Enable and customize preprocessing.
* Error and Warning Options:: How picky should the compiler be?
* Debugging Options:: Symbol tables, measurements, and debugging dumps.
* Directory Options:: Where to find module files
* Link Options :: Influencing the linking step
* Runtime Options:: Influencing runtime behavior
* Code Gen Options:: Specifying conventions for function calls, data layout
and register usage.
@end menu
@node Fortran Dialect Options
@section Options controlling Fortran dialect
@cindex dialect options
......@@ -324,6 +324,17 @@ Specify that no implicit typing is allowed, unless overridden by explicit
@code{IMPLICIT} statements. This is the equivalent of adding
@code{implicit none} to the start of every procedure.
@item -finteger-4-integer-8
@opindex @code{finteger-4-integer-8}
Promote all @code{INTEGER(KIND=4)} entities to an @code{INTEGER(KIND=8)}
entities. If @code{KIND=8} is unavailable, then an error will be issued.
This option should be used with care and may not be suitable for your codes.
Areas of possible concern include calls to external procedures,
alignment in @code{EQUIVALENCE} and/or @code{COMMON}, generic interfaces,
BOZ literal constant conversion, and I/O. Inspection of the intermediate
representation of the translated Fortran code, produced by
@option{-fdump-tree-original}, is suggested.
@item -fcray-pointer
@opindex @code{fcray-pointer}
Enable the Cray pointer extension, which provides C-like pointer
......@@ -354,6 +365,28 @@ Similarly, @code{DATA i/Z'FFFFFFFF'/} will result in an integer overflow
on most systems, but with @option{-fno-range-check} the value will
``wrap around'' and @code{i} will be initialized to @math{-1} instead.
@item -freal-4-real-8
@itemx -freal-4-real-10
@itemx -freal-8-real-4
@itemx -freal-8-real-10
@itemx -freal-8-real-16
@opindex @code{freal-4-real-8}
@opindex @code{freal-4-real-10}
@opindex @code{freal-4-real-16}
@opindex @code{freal-8-real-4}
@opindex @code{freal-8-real-10}
@opindex @code{freal-8-real-16}
@cindex options, real kind type promotion
Promote all @code{REAL(KIND=M)} entities to @code{REAL(KIND=N)} entities.
If @code{REAL(KIND=N)} is unavailable, then an error will be issued.
All other real kind types are unaffected by this option.
These options should be used with care and may not be suitable for your
codes. Areas of possible concern include calls to external procedures,
alignment in @code{EQUIVALENCE} and/or @code{COMMON}, generic interfaces,
BOZ literal constant conversion, and I/O. Inspection of the intermediate
representation of the translated Fortran code, produced by
@option{-fdump-tree-original}, is suggested.
@item -std=@var{std}
@opindex @code{std=}@var{std} option
Specify the standard to which the program is expected to conform, which
......
; Options for the Fortran 95 front end.
; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
; Free Software Foundation, Inc.
;
; This file is part of GCC.
......@@ -394,6 +394,10 @@ ffixed-form
Fortran RejectNegative
Assume that the source file is fixed form
finteger-4-integer-8
Fortran RejectNegative
Interpret any INTEGER(4) as an INTEGER(8)
fintrinsic-modules-path
Fortran RejectNegative Joined Separate
Specify where to find the compiled intrinsic modules
......@@ -494,6 +498,30 @@ frange-check
Fortran
Enable range checking during compilation
freal-4-real-8
Fortran RejectNegative
Interpret any REAl(4) as a REAL(8)
freal-4-real-10
Fortran RejectNegative
Interpret any REAL(4) as a REAL(10)
freal-4-real-16
Fortran RejectNegative
Interpret any REAL(4) as a REAl(16)
freal-8-real-4
Fortran RejectNegative
Interpret any REAL(8) as a REAL(4)
freal-8-real-10
Fortran RejectNegative
Interpret any REAL(8) as a REAL(10)
freal-8-real-16
Fortran RejectNegative
Interpret any REAL(8) as a REAl(16)
frealloc-lhs
Fortran
Reallocate the LHS in assignments
......
/* Parse and display command line options.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
2009, 2010, 2011
2009, 2010, 2011, 2012
Free Software Foundation, Inc.
Contributed by Andy Vaught
......@@ -116,6 +116,9 @@ gfc_init_options (unsigned int decoded_options_count,
gfc_option.flag_default_double = 0;
gfc_option.flag_default_integer = 0;
gfc_option.flag_default_real = 0;
gfc_option.flag_integer4_kind = 0;
gfc_option.flag_real4_kind = 0;
gfc_option.flag_real8_kind = 0;
gfc_option.flag_dollar_ok = 0;
gfc_option.flag_underscoring = 1;
gfc_option.flag_whole_file = 1;
......@@ -849,6 +852,34 @@ gfc_handle_option (size_t scode, const char *arg, int value,
gfc_option.flag_default_double = value;
break;
case OPT_finteger_4_integer_8:
gfc_option.flag_integer4_kind = 8;
break;
case OPT_freal_4_real_8:
gfc_option.flag_real4_kind = 8;
break;
case OPT_freal_4_real_10:
gfc_option.flag_real4_kind = 10;
break;
case OPT_freal_4_real_16:
gfc_option.flag_real4_kind = 16;
break;
case OPT_freal_8_real_4:
gfc_option.flag_real8_kind = 4;
break;
case OPT_freal_8_real_10:
gfc_option.flag_real8_kind = 10;
break;
case OPT_freal_8_real_16:
gfc_option.flag_real8_kind = 16;
break;
case OPT_finit_local_zero:
gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
gfc_option.flag_init_integer_value = 0;
......
/* Primary expression subroutines
Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2011, 2012
Free Software Foundation, Inc.
Contributed by Andy Vaught
......@@ -224,6 +225,9 @@ match_integer_constant (gfc_expr **result, int signflag)
if (kind == -1)
return MATCH_ERROR;
if (kind == 4 && gfc_option.flag_integer4_kind == 8)
kind = 8;
if (gfc_validate_kind (BT_INTEGER, kind, true) < 0)
{
gfc_error ("Integer kind %d at %C not available", kind);
......@@ -636,6 +640,26 @@ done:
goto cleanup;
}
kind = gfc_default_double_kind;
if (kind == 4)
{
if (gfc_option.flag_real4_kind == 8)
kind = 8;
if (gfc_option.flag_real4_kind == 10)
kind = 10;
if (gfc_option.flag_real4_kind == 16)
kind = 16;
}
if (kind == 8)
{
if (gfc_option.flag_real8_kind == 4)
kind = 4;
if (gfc_option.flag_real8_kind == 10)
kind = 10;
if (gfc_option.flag_real8_kind == 16)
kind = 16;
}
break;
case 'q':
......@@ -666,6 +690,26 @@ done:
if (kind == -2)
kind = gfc_default_real_kind;
if (kind == 4)
{
if (gfc_option.flag_real4_kind == 8)
kind = 8;
if (gfc_option.flag_real4_kind == 10)
kind = 10;
if (gfc_option.flag_real4_kind == 16)
kind = 16;
}
if (kind == 8)
{
if (gfc_option.flag_real8_kind == 4)
kind = 4;
if (gfc_option.flag_real8_kind == 10)
kind = 10;
if (gfc_option.flag_real8_kind == 16)
kind = 16;
}
if (gfc_validate_kind (BT_REAL, kind, true) < 0)
{
gfc_error ("Invalid real kind %d at %C", kind);
......
/* Backend support for Fortran 95 basic types and derived types.
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2010, 2011
2010, 2011, 2012
Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
and Steven Bosscher <s.bosscher@student.tudelft.nl>
......@@ -362,7 +362,7 @@ gfc_init_kinds (void)
unsigned int mode;
int i_index, r_index, kind;
bool saw_i4 = false, saw_i8 = false;
bool saw_r4 = false, saw_r8 = false, saw_r16 = false;
bool saw_r4 = false, saw_r8 = false, saw_r10 = false, saw_r16 = false;
for (i_index = 0, mode = MIN_MODE_INT; mode <= MAX_MODE_INT; mode++)
{
......@@ -456,6 +456,8 @@ gfc_init_kinds (void)
saw_r4 = true;
if (kind == 8)
saw_r8 = true;
if (kind == 10)
saw_r10 = true;
if (kind == 16)
saw_r16 = true;
......@@ -482,23 +484,31 @@ gfc_init_kinds (void)
r_index += 1;
}
/* Choose the default integer kind. We choose 4 unless the user
directs us otherwise. */
/* Choose the default integer kind. We choose 4 unless the user directs us
otherwise. Even if the user specified that the default integer kind is 8,
the numeric storage size is not 64 bits. In this case, a warning will be
issued when NUMERIC_STORAGE_SIZE is used. Set NUMERIC_STORAGE_SIZE to 32. */
gfc_numeric_storage_size = 4 * 8;
if (gfc_option.flag_default_integer)
{
if (!saw_i8)
fatal_error ("integer kind=8 not available for -fdefault-integer-8 option");
fatal_error ("INTEGER(KIND=8) is not available for -fdefault-integer-8 option");
gfc_default_integer_kind = 8;
/* Even if the user specified that the default integer kind be 8,
the numeric storage size isn't 64. In this case, a warning will
be issued when NUMERIC_STORAGE_SIZE is used. */
gfc_numeric_storage_size = 4 * 8;
}
else if (gfc_option.flag_integer4_kind == 8)
{
if (!saw_i8)
fatal_error ("INTEGER(KIND=8) is not available for -finteger-4-integer-8 option");
gfc_default_integer_kind = 8;
}
else if (saw_i4)
{
gfc_default_integer_kind = 4;
gfc_numeric_storage_size = 4 * 8;
}
else
{
......@@ -510,9 +520,31 @@ gfc_init_kinds (void)
if (gfc_option.flag_default_real)
{
if (!saw_r8)
fatal_error ("real kind=8 not available for -fdefault-real-8 option");
fatal_error ("REAL(KIND=8) is not available for -fdefault-real-8 option");
gfc_default_real_kind = 8;
}
else if (gfc_option.flag_real4_kind == 8)
{
if (!saw_r8)
fatal_error ("REAL(KIND=8) is not available for -freal-4-real-8 option");
gfc_default_real_kind = 8;
}
else if (gfc_option.flag_real4_kind == 10)
{
if (!saw_r10)
fatal_error ("REAL(KIND=10) is not available for -freal-4-real-10 option");
gfc_default_real_kind = 10;
}
else if (gfc_option.flag_real4_kind == 16)
{
if (!saw_r16)
fatal_error ("REAL(KIND=16) is not available for -freal-4-real-16 option");
gfc_default_real_kind = 16;
}
else if (saw_r4)
gfc_default_real_kind = 4;
else
......@@ -529,6 +561,27 @@ gfc_init_kinds (void)
gfc_default_double_kind = 8;
else if (gfc_option.flag_default_real && saw_r16)
gfc_default_double_kind = 16;
else if (gfc_option.flag_real8_kind == 4)
{
if (!saw_r4)
fatal_error ("REAL(KIND=4) is not available for -freal-8-real-4 option");
gfc_default_double_kind = 4;
}
else if (gfc_option.flag_real8_kind == 10 )
{
if (!saw_r10)
fatal_error ("REAL(KIND=10) is not available for -freal-8-real-10 option");
gfc_default_double_kind = 10;
}
else if (gfc_option.flag_real8_kind == 16 )
{
if (!saw_r16)
fatal_error ("REAL(KIND=10) is not available for -freal-8-real-16 option");
gfc_default_double_kind = 16;
}
else if (saw_r4 && saw_r8)
gfc_default_double_kind = 8;
else
......
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