+2009-03-27 Tobias Burnus <burnus@net-b.de>
+
+ * gfortran.h (enum init_local_real.): Add GFC_INIT_REAL_SNAN.
+ (gfc_expr): Add is_snan.
+ * trans-const.c (gfc_conv_mpfr_to_tree): Support SNaN.
+ (gfc_conv_constant_to_tree): Update call to gfc_conv_mpfr_to_tree.
+ * trans-const.h (gfc_conv_mpfr_to_tree): Update prototype.
+ * resolve.c (build_default_init_expr): Update call.
+ * target-memory.c (encode_float): Ditto.
+ * trans-intrinsic.c (gfc_conv_intrinsic_aint,gfc_conv_intrinsic_mod,
+
2009-03-18 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* lang.opt: Unify help texts for -I, -Wconversion, -d, -fopenmp,
GFC_INIT_REAL_OFF = 0,
GFC_INIT_REAL_ZERO,
GFC_INIT_REAL_NAN,
+ GFC_INIT_REAL_SNAN,
GFC_INIT_REAL_INF,
GFC_INIT_REAL_NEG_INF
}
locus where;
/* True if the expression is a call to a function that returns an array,
- and if we have decided not to allocate temporary data for that array. */
- unsigned int inline_noncopying_intrinsic : 1, is_boz : 1;
+ and if we have decided not to allocate temporary data for that array.
+ is_boz is true if the integer is regarded as BOZ bitpatten and is_snan
+ denotes a signalling not-a-number. */
+ unsigned int inline_noncopying_intrinsic : 1, is_boz : 1, is_snan : 1;
/* Sometimes, when an error has been emitted, it is necessary to prevent
it from recurring. */
-fmax-stack-var-size=@var{n} @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>} @gol
+-finit-integer=@var{n} -finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
-finit-logical=@var{<true|false>} -finit-character=@var{n} -fno-align-commons}
@end table
@item -finit-local-zero
@item -finit-integer=@var{n}
-@item -finit-real=@var{<zero|inf|-inf|nan>}
+@item -finit-real=@var{<zero|inf|-inf|nan|snan>}
@item -finit-logical=@var{<true|false>}
@item -finit-character=@var{n}
@opindex @code{finit-local-zero}
@code{CHARACTER} variables to a string of null bytes. Finer-grained
initialization options are provided by the
@option{-finit-integer=@var{n}},
-@option{-finit-real=@var{<zero|inf|-inf|nan>}} (which also initializes
+@option{-finit-real=@var{<zero|inf|-inf|nan|snan>}} (which also initializes
the real and imaginary parts of local @code{COMPLEX} variables),
@option{-finit-logical=@var{<true|false>}}, and
@option{-finit-character=@var{n}} (where @var{n} is an ASCII character
future releases).
Note that the @option{-finit-real=nan} option initializes @code{REAL}
-and @code{COMPLEX} variables with a quiet NaN.
+and @code{COMPLEX} variables with a quiet NaN. For a signalling NaN
+use @option{-finit-real=snan}; note, however, that compile-time
+optimizations may convert them into quiet NaN and that trapping
+needs to be enabled (e.g. via @option{-ffpe-trap}).
@item -falign-commons
@opindex @code{falign-commons}
gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
else if (!strcasecmp (arg, "nan"))
gfc_option.flag_init_real = GFC_INIT_REAL_NAN;
+ else if (!strcasecmp (arg, "snan"))
+ gfc_option.flag_init_real = GFC_INIT_REAL_SNAN;
else if (!strcasecmp (arg, "inf"))
gfc_option.flag_init_real = GFC_INIT_REAL_INF;
else if (!strcasecmp (arg, "-inf"))
mpfr_init (init_expr->value.real);
switch (gfc_option.flag_init_real)
{
+ case GFC_INIT_REAL_SNAN:
+ init_expr->is_snan = 1;
+ /* Fall through. */
case GFC_INIT_REAL_NAN:
mpfr_set_nan (init_expr->value.real);
break;
mpfr_init (init_expr->value.complex.i);
switch (gfc_option.flag_init_real)
{
+ case GFC_INIT_REAL_SNAN:
+ init_expr->is_snan = 1;
+ /* Fall through. */
case GFC_INIT_REAL_NAN:
mpfr_set_nan (init_expr->value.complex.r);
mpfr_set_nan (init_expr->value.complex.i);
static int
encode_float (int kind, mpfr_t real, unsigned char *buffer, size_t buffer_size)
{
- return native_encode_expr (gfc_conv_mpfr_to_tree (real, kind), buffer,
+ return native_encode_expr (gfc_conv_mpfr_to_tree (real, kind, 0), buffer,
buffer_size);
}
/* Converts a real constant into backend form. */
tree
-gfc_conv_mpfr_to_tree (mpfr_t f, int kind)
+gfc_conv_mpfr_to_tree (mpfr_t f, int kind, int is_snan)
{
tree type;
int n;
gcc_assert (gfc_real_kinds[n].radix == 2);
type = gfc_get_real_type (kind);
- real_from_mpfr (&real, f, type, GFC_RND_MODE);
+ if (mpfr_nan_p (f) && is_snan)
+ real_from_string (&real, "SNaN");
+ else
+ real_from_mpfr (&real, f, type, GFC_RND_MODE);
+
return build_real (type, real);
}
gfc_build_string_const (expr->representation.length,
expr->representation.string));
else
- return gfc_conv_mpfr_to_tree (expr->value.real, expr->ts.kind);
+ return gfc_conv_mpfr_to_tree (expr->value.real, expr->ts.kind, expr->is_snan);
case BT_LOGICAL:
if (expr->representation.string)
else
{
tree real = gfc_conv_mpfr_to_tree (expr->value.complex.r,
- expr->ts.kind);
+ expr->ts.kind, expr->is_snan);
tree imag = gfc_conv_mpfr_to_tree (expr->value.complex.i,
- expr->ts.kind);
+ expr->ts.kind, expr->is_snan);
return build_complex (gfc_typenode_for_spec (&expr->ts),
real, imag);
void gfc_conv_tree_to_mpz (mpz_t, tree);
/* Converts between REAL_CST and MPFR floating-point representations. */
-tree gfc_conv_mpfr_to_tree (mpfr_t, int);
+tree gfc_conv_mpfr_to_tree (mpfr_t, int, int);
void gfc_conv_tree_to_mpfr (mpfr_ptr, tree);
/* Build a tree for a constant. Must be an EXPR_CONSTANT gfc_expr.
mpfr_init (huge);
n = gfc_validate_kind (BT_INTEGER, kind, false);
mpfr_set_z (huge, gfc_integer_kinds[n].huge, GFC_RND_MODE);
- tmp = gfc_conv_mpfr_to_tree (huge, kind);
+ tmp = gfc_conv_mpfr_to_tree (huge, kind, 0);
cond = fold_build2 (LT_EXPR, boolean_type_node, arg[0], tmp);
mpfr_neg (huge, huge, GFC_RND_MODE);
- tmp = gfc_conv_mpfr_to_tree (huge, kind);
+ tmp = gfc_conv_mpfr_to_tree (huge, kind, 0);
tmp = fold_build2 (GT_EXPR, boolean_type_node, arg[0], tmp);
cond = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, cond, tmp);
itype = gfc_get_int_type (kind);
ikind = gfc_max_integer_kind;
}
mpfr_set_z (huge, gfc_integer_kinds[n].huge, GFC_RND_MODE);
- test = gfc_conv_mpfr_to_tree (huge, expr->ts.kind);
+ test = gfc_conv_mpfr_to_tree (huge, expr->ts.kind, 0);
test2 = fold_build2 (LT_EXPR, boolean_type_node, tmp, test);
mpfr_neg (huge, huge, GFC_RND_MODE);
- test = gfc_conv_mpfr_to_tree (huge, expr->ts.kind);
+ test = gfc_conv_mpfr_to_tree (huge, expr->ts.kind, 0);
test = fold_build2 (GT_EXPR, boolean_type_node, tmp, test);
test2 = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, test, test2);
switch (arrayexpr->ts.type)
{
case BT_REAL:
- tmp = gfc_conv_mpfr_to_tree (gfc_real_kinds[n].huge, arrayexpr->ts.kind);
+ tmp = gfc_conv_mpfr_to_tree (gfc_real_kinds[n].huge,
+ arrayexpr->ts.kind, 0);
break;
case BT_INTEGER:
switch (expr->ts.type)
{
case BT_REAL:
- tmp = gfc_conv_mpfr_to_tree (gfc_real_kinds[n].huge, expr->ts.kind);
+ tmp = gfc_conv_mpfr_to_tree (gfc_real_kinds[n].huge, expr->ts.kind, 0);
break;
case BT_INTEGER:
k = gfc_validate_kind (BT_REAL, expr->ts.kind, false);
prec = build_int_cst (NULL_TREE, gfc_real_kinds[k].digits);
emin = build_int_cst (NULL_TREE, gfc_real_kinds[k].min_exponent - 1);
- tiny = gfc_conv_mpfr_to_tree (gfc_real_kinds[k].tiny, expr->ts.kind);
+ tiny = gfc_conv_mpfr_to_tree (gfc_real_kinds[k].tiny, expr->ts.kind, 0);
switch (expr->ts.kind)
{