check.c (gfc_check_atan_2): Typo in comment.

2011-10-28  Steven G. Kargl  <kargl@gcc.gnu.org>

	* check.c (gfc_check_atan_2): Typo in comment.
	(gfc_check_nearest): If 's' is constant, check that it is not 0.
	* simplify.c (simplify_dshift, gfc_simplify_ibclr, gfc_simplify_ibits,
	gfc_simplify_ibset, simplify_shift, gfc_simplify_ishftc,
	gfc_simplify_nearest): Remove dead code.

2011-10-28  Steven G. Kargl  <kargl@gcc.gnu.org>

	* gfortran.dg/nearest_5.f90: New test.

From-SVN: r180618
This commit is contained in:
Steven G. Kargl 2011-10-28 15:15:25 +00:00
parent e8a25ac83c
commit 58a9e3c406
5 changed files with 43 additions and 75 deletions

View File

@ -1,3 +1,11 @@
2011-10-28 Steven G. Kargl <kargl@gcc.gnu.org>
* check.c (gfc_check_atan_2): Typo in comment.
(gfc_check_nearest): If 's' is constant, check that it is not 0.
* simplify.c (simplify_dshift, gfc_simplify_ibclr, gfc_simplify_ibits,
gfc_simplify_ibset, simplify_shift, gfc_simplify_ishftc,
gfc_simplify_nearest): Remove dead code.
2011-10-23 Steven G. Kargl <kargl@gcc.gnu.org> 2011-10-23 Steven G. Kargl <kargl@gcc.gnu.org>
* simplify.c (simplify_transformation_to_array): Fix memory leak. * simplify.c (simplify_transformation_to_array): Fix memory leak.

View File

@ -934,7 +934,7 @@ null_arg:
gfc_try gfc_try
gfc_check_atan_2 (gfc_expr *y, gfc_expr *x) gfc_check_atan_2 (gfc_expr *y, gfc_expr *x)
{ {
/* gfc_notify_std would be a wast of time as the return value /* gfc_notify_std would be a waste of time as the return value
is seemingly used only for the generic resolution. The error is seemingly used only for the generic resolution. The error
will be: Too many arguments. */ will be: Too many arguments. */
if ((gfc_option.allow_std & GFC_STD_F2008) == 0) if ((gfc_option.allow_std & GFC_STD_F2008) == 0)
@ -2710,6 +2710,16 @@ gfc_check_nearest (gfc_expr *x, gfc_expr *s)
if (type_check (s, 1, BT_REAL) == FAILURE) if (type_check (s, 1, BT_REAL) == FAILURE)
return FAILURE; return FAILURE;
if (s->expr_type == EXPR_CONSTANT)
{
if (mpfr_sgn (s->value.real) == 0)
{
gfc_error ("Argument 'S' of NEAREST at %L shall not be zero",
&s->where);
return FAILURE;
}
}
return SUCCESS; return SUCCESS;
} }

View File

@ -1899,13 +1899,7 @@ simplify_dshift (gfc_expr *arg1, gfc_expr *arg2, gfc_expr *shiftarg,
k = gfc_validate_kind (BT_INTEGER, arg1->ts.kind, false); k = gfc_validate_kind (BT_INTEGER, arg1->ts.kind, false);
size = gfc_integer_kinds[k].bit_size; size = gfc_integer_kinds[k].bit_size;
if (gfc_extract_int (shiftarg, &shift) != NULL) gfc_extract_int (shiftarg, &shift);
{
gfc_error ("Invalid SHIFT argument of DSHIFTL at %L", &shiftarg->where);
return &gfc_bad_expr;
}
gcc_assert (shift >= 0 && shift <= size);
/* DSHIFTR(I,J,SHIFT) = DSHIFTL(I,J,SIZE-SHIFT). */ /* DSHIFTR(I,J,SHIFT) = DSHIFTL(I,J,SIZE-SHIFT). */
if (right) if (right)
@ -2509,21 +2503,10 @@ gfc_simplify_ibclr (gfc_expr *x, gfc_expr *y)
if (x->expr_type != EXPR_CONSTANT || y->expr_type != EXPR_CONSTANT) if (x->expr_type != EXPR_CONSTANT || y->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
if (gfc_extract_int (y, &pos) != NULL || pos < 0) gfc_extract_int (y, &pos);
{
gfc_error ("Invalid second argument of IBCLR at %L", &y->where);
return &gfc_bad_expr;
}
k = gfc_validate_kind (x->ts.type, x->ts.kind, false); k = gfc_validate_kind (x->ts.type, x->ts.kind, false);
if (pos >= gfc_integer_kinds[k].bit_size)
{
gfc_error ("Second argument of IBCLR exceeds bit size at %L",
&y->where);
return &gfc_bad_expr;
}
result = gfc_copy_expr (x); result = gfc_copy_expr (x);
convert_mpz_to_unsigned (result->value.integer, convert_mpz_to_unsigned (result->value.integer,
@ -2551,17 +2534,8 @@ gfc_simplify_ibits (gfc_expr *x, gfc_expr *y, gfc_expr *z)
|| z->expr_type != EXPR_CONSTANT) || z->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
if (gfc_extract_int (y, &pos) != NULL || pos < 0) gfc_extract_int (y, &pos);
{ gfc_extract_int (z, &len);
gfc_error ("Invalid second argument of IBITS at %L", &y->where);
return &gfc_bad_expr;
}
if (gfc_extract_int (z, &len) != NULL || len < 0)
{
gfc_error ("Invalid third argument of IBITS at %L", &z->where);
return &gfc_bad_expr;
}
k = gfc_validate_kind (BT_INTEGER, x->ts.kind, false); k = gfc_validate_kind (BT_INTEGER, x->ts.kind, false);
@ -2614,21 +2588,10 @@ gfc_simplify_ibset (gfc_expr *x, gfc_expr *y)
if (x->expr_type != EXPR_CONSTANT || y->expr_type != EXPR_CONSTANT) if (x->expr_type != EXPR_CONSTANT || y->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
if (gfc_extract_int (y, &pos) != NULL || pos < 0) gfc_extract_int (y, &pos);
{
gfc_error ("Invalid second argument of IBSET at %L", &y->where);
return &gfc_bad_expr;
}
k = gfc_validate_kind (x->ts.type, x->ts.kind, false); k = gfc_validate_kind (x->ts.type, x->ts.kind, false);
if (pos >= gfc_integer_kinds[k].bit_size)
{
gfc_error ("Second argument of IBSET exceeds bit size at %L",
&y->where);
return &gfc_bad_expr;
}
result = gfc_copy_expr (x); result = gfc_copy_expr (x);
convert_mpz_to_unsigned (result->value.integer, convert_mpz_to_unsigned (result->value.integer,
@ -3004,11 +2967,8 @@ simplify_shift (gfc_expr *e, gfc_expr *s, const char *name,
if (e->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT) if (e->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
if (gfc_extract_int (s, &shift) != NULL)
{ gfc_extract_int (s, &shift);
gfc_error ("Invalid second argument of %s at %L", name, &s->where);
return &gfc_bad_expr;
}
k = gfc_validate_kind (BT_INTEGER, e->ts.kind, false); k = gfc_validate_kind (BT_INTEGER, e->ts.kind, false);
bitsize = gfc_integer_kinds[k].bit_size; bitsize = gfc_integer_kinds[k].bit_size;
@ -3146,11 +3106,7 @@ gfc_simplify_ishftc (gfc_expr *e, gfc_expr *s, gfc_expr *sz)
if (e->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT) if (e->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
if (gfc_extract_int (s, &shift) != NULL) gfc_extract_int (s, &shift);
{
gfc_error ("Invalid second argument of ISHFTC at %L", &s->where);
return &gfc_bad_expr;
}
k = gfc_validate_kind (e->ts.type, e->ts.kind, false); k = gfc_validate_kind (e->ts.type, e->ts.kind, false);
isize = gfc_integer_kinds[k].bit_size; isize = gfc_integer_kinds[k].bit_size;
@ -3160,18 +3116,8 @@ gfc_simplify_ishftc (gfc_expr *e, gfc_expr *s, gfc_expr *sz)
if (sz->expr_type != EXPR_CONSTANT) if (sz->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
if (gfc_extract_int (sz, &ssize) != NULL || ssize <= 0) gfc_extract_int (sz, &ssize);
{
gfc_error ("Invalid third argument of ISHFTC at %L", &sz->where);
return &gfc_bad_expr;
}
if (ssize > isize)
{
gfc_error ("Magnitude of third argument of ISHFTC exceeds "
"BIT_SIZE of first argument at %L", &s->where);
return &gfc_bad_expr;
}
} }
else else
ssize = isize; ssize = isize;
@ -3183,10 +3129,7 @@ gfc_simplify_ishftc (gfc_expr *e, gfc_expr *s, gfc_expr *sz)
if (ashift > ssize) if (ashift > ssize)
{ {
if (sz != NULL) if (sz == NULL)
gfc_error ("Magnitude of second argument of ISHFTC exceeds "
"third argument at %L", &s->where);
else
gfc_error ("Magnitude of second argument of ISHFTC exceeds " gfc_error ("Magnitude of second argument of ISHFTC exceeds "
"BIT_SIZE of first argument at %L", &s->where); "BIT_SIZE of first argument at %L", &s->where);
return &gfc_bad_expr; return &gfc_bad_expr;
@ -4382,13 +4325,6 @@ gfc_simplify_nearest (gfc_expr *x, gfc_expr *s)
if (x->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT) if (x->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
if (mpfr_sgn (s->value.real) == 0)
{
gfc_error ("Second argument of NEAREST at %L shall not be zero",
&s->where);
return &gfc_bad_expr;
}
result = gfc_copy_expr (x); result = gfc_copy_expr (x);
/* Save current values of emin and emax. */ /* Save current values of emin and emax. */

View File

@ -1,3 +1,7 @@
2011-10-28 Steven G. Kargl <kargl@gcc.gnu.org>
* gfortran.dg/nearest_5.f90: New test.
2011-10-28 Jakub Jelinek <jakub@redhat.com> 2011-10-28 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/vshift-1.c: New test. * gcc.dg/vshift-1.c: New test.

View File

@ -0,0 +1,10 @@
! { dg-do compile }
program a
real x, y(2)
x = 1./3.
y = [1, 2] / 3.
print *, nearest(x, 0.) ! { dg-error "shall not be zero" }
print *, nearest(y, 0.) ! { dg-error "shall not be zero" }
print *, nearest([1., 2.] / 3., 0.) ! { dg-error "shall not be zero" }
print *, nearest(1., 0.) ! { dg-error "shall not be zero" }
end program a