+2004-08-25 Richard Henderson <rth@redhat.com>
+
+ * arith.c (gfc_validate_kind): Add may_fail argument; abort if
+ false and we don't validate the kind.
+ (gfc_check_integer_range, gfc_check_real_range): Update to match.
+ * check.c (kind_check): Likewise.
+ * decl.c (gfc_match_old_kind_spec, gfc_match_kind_spec): Likewise.
+ (match_char_spec, match_logical_spec): Likewise.
+ * gfortran.h (gfc_validate_kind): Likewise.
+ * options.c (gfc_handle_option): Likewise.
+ * primary.c (match_integer_constant, match_real_constant,
+ match_string_constant, match_logical_constant,
+ match_const_complex_part): Likewise.
+ * simplify.c (get_kind, gfc_simplify_bit_size, gfc_simplify_digits,
+ gfc_simplify_epsilon, gfc_simplify_huge, gfc_simplify_ibclr,
+ gfc_simplify_ibset, gfc_simplify_ishft, gfc_simplify_ishftc,
+ gfc_simplify_maxexponent, gfc_simplify_minexponent,
+ gfc_simplify_nearest, gfc_simplify_not, gfc_simplify_precision,
+ gfc_simplify_radix, gfc_simplify_range, gfc_simplify_rrspacing,
+ gfc_simplify_scale, gfc_simplify_spacing, gfc_simplify_tan,
+ gfc_simplify_tiny): Likewise.
+ * trans-intrinsic.c (gfc_conv_intrinsic_aint, gfc_conv_intrinsic_mod,
+ gfc_conv_intrinsic_minmaxloc, gfc_conv_intrinsic_minmaxval,
+ prepare_arg_info): Likewise.
+
2004-08-25 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
* expr.c (gfc_check_assign): Add comment. Add new warning.
type. */
int
-gfc_validate_kind (bt type, int kind)
+gfc_validate_kind (bt type, int kind, bool may_fail)
{
int rc;
gfc_internal_error ("gfc_validate_kind(): Got bad type");
}
+ if (!may_fail && rc < 0)
+ gfc_internal_error ("gfc_validate_kind(): Got bad kind");
+
return rc;
}
arith result;
int i;
- i = validate_integer (kind);
- if (i == -1)
- gfc_internal_error ("gfc_check_integer_range(): Bad kind");
-
+ i = gfc_validate_kind (BT_INTEGER, kind, false);
result = ARITH_OK;
if (mpz_cmp (p, gfc_integer_kinds[i].min_int) < 0
mpfr_t q;
int i;
- i = validate_real (kind);
- if (i == -1)
- gfc_internal_error ("gfc_check_real_range(): Bad kind");
+ i = gfc_validate_kind (BT_REAL, kind, false);
gfc_set_model (p);
mpfr_init (q);
}
if (gfc_extract_int (k, &kind) != NULL
- || gfc_validate_kind (type, kind) == -1)
+ || gfc_validate_kind (type, kind, true) < 0)
{
gfc_error ("Invalid kind for %s at %L", gfc_basic_typename (type),
&k->where);
static try
double_check (gfc_expr * d, int n)
{
-
if (type_check (d, n, BT_REAL) == FAILURE)
return FAILURE;
if (ts->type == BT_COMPLEX && ts->kind == 16)
ts->kind = 8;
- if (gfc_validate_kind (ts->type, ts->kind) == -1)
+ if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
{
gfc_error ("Old-style kind %d not supported for type %s at %C",
ts->kind, gfc_basic_typename (ts->type));
gfc_free_expr (e);
e = NULL;
- if (gfc_validate_kind (ts->type, ts->kind) == -1)
+ if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
{
gfc_error ("Kind %d not supported for type %s at %C", ts->kind,
gfc_basic_typename (ts->type));
gfc_match_small_int (&kind);
- if (gfc_validate_kind (BT_CHARACTER, kind) == -1)
+ if (gfc_validate_kind (BT_CHARACTER, kind, true) < 0)
{
gfc_error ("Kind %d is not a CHARACTER kind at %C", kind);
return MATCH_YES;
m = MATCH_ERROR;
done:
- if (m == MATCH_YES && gfc_validate_kind (BT_CHARACTER, kind) == -1)
+ if (m == MATCH_YES && gfc_validate_kind (BT_CHARACTER, kind, true) < 0)
{
gfc_error ("Kind %d is not a CHARACTER kind at %C", kind);
m = MATCH_ERROR;
int gfc_default_character_kind (void);
int gfc_default_logical_kind (void);
int gfc_default_complex_kind (void);
-int gfc_validate_kind (bt, int);
+int gfc_validate_kind (bt, int, bool);
extern int gfc_index_integer_kind;
/* symbol.c */
break;
case OPT_qkind_:
- if (gfc_validate_kind (BT_REAL, value) < 0)
+ if (gfc_validate_kind (BT_REAL, value, true) < 0)
gfc_fatal_error ("Argument to -fqkind isn't a valid real kind");
gfc_option.q_kind = value;
break;
if (kind == -1)
return MATCH_ERROR;
- if (gfc_validate_kind (BT_INTEGER, kind) == -1)
+ if (gfc_validate_kind (BT_INTEGER, kind, true) < 0)
{
gfc_error ("Integer kind %d at %C not available", kind);
return MATCH_ERROR;
if (kind == -2)
kind = gfc_default_real_kind ();
- if (gfc_validate_kind (BT_REAL, kind) == -1)
+ if (gfc_validate_kind (BT_REAL, kind, true) < 0)
{
gfc_error ("Invalid real kind %d at %C", kind);
goto cleanup;
}
}
- if (gfc_validate_kind (BT_CHARACTER, kind) == -1)
+ if (gfc_validate_kind (BT_CHARACTER, kind, true) < 0)
{
gfc_error ("Invalid kind %d for CHARACTER constant at %C", kind);
return MATCH_ERROR;
if (kind == -2)
kind = gfc_default_logical_kind ();
- if (gfc_validate_kind (BT_LOGICAL, kind) == -1)
+ if (gfc_validate_kind (BT_LOGICAL, kind, true) < 0)
gfc_error ("Bad kind for logical constant at %C");
e = gfc_get_expr ();
kind = gfc_default_real_kind ();
}
- if (gfc_validate_kind (BT_REAL, kind) == -1)
+ if (gfc_validate_kind (BT_REAL, kind, true) < 0)
{
gfc_error ("Invalid real kind %d at %C", kind);
return MATCH_ERROR;
}
if (gfc_extract_int (k, &kind) != NULL
- || gfc_validate_kind (type, kind) == -1)
+ || gfc_validate_kind (type, kind, true) < 0)
{
gfc_error ("Invalid KIND parameter of %s at %L", name, &k->where);
gfc_expr *result;
int i;
- i = gfc_validate_kind (e->ts.type, e->ts.kind);
- if (i == -1)
- gfc_internal_error ("In gfc_simplify_bit_size(): Bad kind");
-
+ i = gfc_validate_kind (e->ts.type, e->ts.kind, false);
result = gfc_constant_result (BT_INTEGER, e->ts.kind, &e->where);
mpz_set_ui (result->value.integer, gfc_integer_kinds[i].bit_size);
{
int i, digits;
- i = gfc_validate_kind (x->ts.type, x->ts.kind);
- if (i == -1)
- goto bad;
-
+ i = gfc_validate_kind (x->ts.type, x->ts.kind, false);
switch (x->ts.type)
{
case BT_INTEGER:
break;
default:
- bad:
- gfc_internal_error ("gfc_simplify_digits(): Bad type");
+ abort ();
}
return gfc_int_expr (digits);
gfc_expr *result;
int i;
- i = gfc_validate_kind (e->ts.type, e->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_epsilon(): Bad kind");
+ i = gfc_validate_kind (e->ts.type, e->ts.kind, false);
result = gfc_constant_result (BT_REAL, e->ts.kind, &e->where);
gfc_expr *result;
int i;
- i = gfc_validate_kind (e->ts.type, e->ts.kind);
- if (i == -1)
- goto bad_type;
+ i = gfc_validate_kind (e->ts.type, e->ts.kind, false);
result = gfc_constant_result (e->ts.type, e->ts.kind, &e->where);
mpfr_set (result->value.real, gfc_real_kinds[i].huge, GFC_RND_MODE);
break;
- bad_type:
default:
- gfc_internal_error ("gfc_simplify_huge(): Bad type");
+ abort ();
}
return result;
return &gfc_bad_expr;
}
- k = gfc_validate_kind (x->ts.type, x->ts.kind);
- if (k == -1)
- gfc_internal_error ("gfc_simplify_ibclr(): Bad kind");
+ k = gfc_validate_kind (x->ts.type, x->ts.kind, false);
if (pos > gfc_integer_kinds[k].bit_size)
{
return &gfc_bad_expr;
}
- k = gfc_validate_kind (BT_INTEGER, x->ts.kind);
- if (k == -1)
- gfc_internal_error ("gfc_simplify_ibits(): Bad kind");
+ k = gfc_validate_kind (BT_INTEGER, x->ts.kind, false);
bitsize = gfc_integer_kinds[k].bit_size;
return &gfc_bad_expr;
}
- k = gfc_validate_kind (x->ts.type, x->ts.kind);
- if (k == -1)
- gfc_internal_error ("gfc_simplify_ibset(): Bad kind");
+ k = gfc_validate_kind (x->ts.type, x->ts.kind, false);
if (pos > gfc_integer_kinds[k].bit_size)
{
return &gfc_bad_expr;
}
- k = gfc_validate_kind (BT_INTEGER, e->ts.kind);
- if (k == -1)
- gfc_internal_error ("gfc_simplify_ishft(): Bad kind");
+ k = gfc_validate_kind (BT_INTEGER, e->ts.kind, false);
isize = gfc_integer_kinds[k].bit_size;
return &gfc_bad_expr;
}
- k = gfc_validate_kind (e->ts.type, e->ts.kind);
- if (k == -1)
- gfc_internal_error ("gfc_simplify_ishftc(): Bad kind");
+ k = gfc_validate_kind (e->ts.type, e->ts.kind, false);
if (sz != NULL)
{
gfc_expr *result;
int i;
- i = gfc_validate_kind (BT_REAL, x->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_maxexponent(): Bad kind");
+ i = gfc_validate_kind (BT_REAL, x->ts.kind, false);
result = gfc_int_expr (gfc_real_kinds[i].max_exponent);
result->where = x->where;
gfc_expr *result;
int i;
- i = gfc_validate_kind (BT_REAL, x->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_minexponent(): Bad kind");
+ i = gfc_validate_kind (BT_REAL, x->ts.kind, false);
result = gfc_int_expr (gfc_real_kinds[i].min_exponent);
result->where = x->where;
if (x->expr_type != EXPR_CONSTANT)
return NULL;
- k = gfc_validate_kind (x->ts.type, x->ts.kind);
- if (k == -1)
- gfc_internal_error ("gfc_simplify_precision(): Bad kind");
+ k = gfc_validate_kind (x->ts.type, x->ts.kind, false);
result = gfc_constant_result (x->ts.type, x->ts.kind, &x->where);
/* Because of how GMP handles numbers, the result must be ANDed with
the max_int mask. For radices <> 2, this will require change. */
- i = gfc_validate_kind (BT_INTEGER, e->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_not(): Bad kind");
+ i = gfc_validate_kind (BT_INTEGER, e->ts.kind, false);
mpz_and (result->value.integer, result->value.integer,
gfc_integer_kinds[i].max_int);
gfc_expr *result;
int i;
- i = gfc_validate_kind (e->ts.type, e->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_precision(): Bad kind");
+ i = gfc_validate_kind (e->ts.type, e->ts.kind, false);
result = gfc_int_expr (gfc_real_kinds[i].precision);
result->where = e->where;
gfc_expr *result;
int i;
- i = gfc_validate_kind (e->ts.type, e->ts.kind);
- if (i == -1)
- goto bad;
-
+ i = gfc_validate_kind (e->ts.type, e->ts.kind, false);
switch (e->ts.type)
{
case BT_INTEGER:
break;
default:
- bad:
- gfc_internal_error ("gfc_simplify_radix(): Bad type");
+ abort ();
}
result = gfc_int_expr (i);
int i;
long j;
- i = gfc_validate_kind (e->ts.type, e->ts.kind);
- if (i == -1)
- goto bad_type;
+ i = gfc_validate_kind (e->ts.type, e->ts.kind, false);
switch (e->ts.type)
{
j = gfc_real_kinds[i].range;
break;
- bad_type:
default:
- gfc_internal_error ("gfc_simplify_range(): Bad kind");
+ abort ();
}
result = gfc_int_expr (j);
if (x->expr_type != EXPR_CONSTANT)
return NULL;
- i = gfc_validate_kind (x->ts.type, x->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_rrspacing(): Bad kind");
+ i = gfc_validate_kind (x->ts.type, x->ts.kind, false);
result = gfc_constant_result (BT_REAL, x->ts.kind, &x->where);
return result;
}
- k = gfc_validate_kind (BT_REAL, x->ts.kind);
- if (k == -1)
- gfc_internal_error ("gfc_simplify_scale(): Bad kind");
+ k = gfc_validate_kind (BT_REAL, x->ts.kind, false);
exp_range = gfc_real_kinds[k].max_exponent - gfc_real_kinds[k].min_exponent;
if (x->expr_type != EXPR_CONSTANT)
return NULL;
- i = gfc_validate_kind (x->ts.type, x->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_spacing(): Bad kind");
+ i = gfc_validate_kind (x->ts.type, x->ts.kind, false);
p = gfc_real_kinds[i].digits;
if (x->expr_type != EXPR_CONSTANT)
return NULL;
- i = gfc_validate_kind (BT_REAL, x->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_tan(): Bad kind");
+ i = gfc_validate_kind (BT_REAL, x->ts.kind, false);
result = gfc_constant_result (x->ts.type, x->ts.kind, &x->where);
gfc_expr *result;
int i;
- i = gfc_validate_kind (BT_REAL, e->ts.kind);
- if (i == -1)
- gfc_internal_error ("gfc_simplify_error(): Bad kind");
+ i = gfc_validate_kind (BT_REAL, e->ts.kind, false);
result = gfc_constant_result (BT_REAL, e->ts.kind, &e->where);
mpfr_set (result->value.real, gfc_real_kinds[i].tiny, GFC_RND_MODE);
/* Test if the value is too large to handle sensibly. */
gfc_set_model_kind (kind);
mpfr_init (huge);
- n = gfc_validate_kind (BT_INTEGER, kind);
+ 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);
cond = build2 (LT_EXPR, boolean_type_node, arg, tmp);
/* Test if the value is too large to handle sensibly. */
gfc_set_model_kind (expr->ts.kind);
mpfr_init (huge);
- n = gfc_validate_kind (BT_INTEGER, expr->ts.kind);
+ n = gfc_validate_kind (BT_INTEGER, expr->ts.kind, false);
mpfr_set_z (huge, gfc_integer_kinds[n].huge, GFC_RND_MODE);
test = gfc_conv_mpfr_to_tree (huge, expr->ts.kind);
test2 = build2 (LT_EXPR, boolean_type_node, tmp, test);
maskss = NULL;
limit = gfc_create_var (gfc_typenode_for_spec (&arrayexpr->ts), "limit");
- n = gfc_validate_kind (arrayexpr->ts.type, arrayexpr->ts.kind);
+ n = gfc_validate_kind (arrayexpr->ts.type, arrayexpr->ts.kind, false);
switch (arrayexpr->ts.type)
{
case BT_REAL:
type = gfc_typenode_for_spec (&expr->ts);
/* Initialize the result. */
limit = gfc_create_var (type, "limit");
- n = gfc_validate_kind (expr->ts.type, expr->ts.kind);
+ n = gfc_validate_kind (expr->ts.type, expr->ts.kind, false);
switch (expr->ts.type)
{
case BT_REAL:
rcs->arg = arg;
/* Caculate the numbers of bits of exponent, fraction and word */
- n = gfc_validate_kind (a1->ts.type, a1->ts.kind);
+ n = gfc_validate_kind (a1->ts.type, a1->ts.kind, false);
tmp = build_int_cst (NULL_TREE, gfc_real_kinds[n].digits - 1);
rcs->fdigits = convert (masktype, tmp);
wbits = build_int_cst (NULL_TREE, TYPE_PRECISION (rcs->type) - 1);