re PR fortran/30512 ([4.1 only] MAXVAL() incorrect for zero-size int arrays, and for -HUGE-1 maximum values.)

fortran/
2007-02-09  Tobias Burnus  <burnus@net-b.de>

        PR fortran/30512
        * trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc,
	  gfc_conv_intrinsic_minmaxval): Use HUGE-1 for most negative integer.

testsuite/
2007-02-09  Tobias Burnus  <burnus@net-b.de>

        PR fortran/30512
        * gfortran.dg/maxlocval_1.f90: New test.

libgfortran/
2007-02-09  Thomas Koenig  <Thomas.Koenig@online.de>
	    Tobias Burnus  <burnus@net-b.de>

        PR fortran/30512
        * m4/iparm.m4: Use HUGE-1 for most negative integer.
	* generated/maxloc1_8_i4.c: Regenerate.
	* generated/maxloc0_8_i8.c: Regenerate.
	* generated/maxloc1_16_i4.c: Regenerate.
	* generated/maxloc0_16_i8.c: Regenerate.
	* generated/maxval_i4.c: Regenerate.
	* generated/maxloc1_4_i8.c: Regenerate.
	* generated/maxloc0_16_i16.c: Regenerate.
	* generated/maxloc1_4_i16.c: Regenerate.
	* generated/maxloc0_8_i16.c: Regenerate.
	* generated/maxloc0_4_i4.c: Regenerate.
	* generated/maxloc1_8_i8.c: Regenerate.
	* generated/maxloc0_8_i4.c: Regenerate.
	* generated/maxloc0_16_i4.c: Regenerate.
	* generated/maxloc1_16_i8.c: Regenerate.
	* generated/maxloc1_4_i4.c: Regenerate.
	* generated/maxval_i8.c: Regenerate.
	* generated/maxloc0_4_i16.c: Regenerate.
	* generated/maxloc1_8_i16.c: Regenerate.
	* generated/maxloc0_4_i8.c: Regenerate.
	* generated/maxloc1_16_i16.c: Regenerate.
	* generated/maxval_i16.c: Regenerate.

From-SVN: r121777
This commit is contained in:
Tobias Burnus 2007-02-09 22:56:06 +01:00
parent ff848f0e0f
commit 8811602900
27 changed files with 151 additions and 54 deletions

View File

@ -1,3 +1,9 @@
2007-02-09 Tobias Burnus <burnus@net-b.de>
PR fortran/30512
* trans-intrinsic.c (gfc_conv_intrinsic_minmaxloc,
gfc_conv_intrinsic_minmaxval): Use HUGE-1 for most negative integer.
2007-02-09 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR fortran/30720

View File

@ -1984,11 +1984,18 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, int op)
gcc_unreachable ();
}
/* Most negative(+HUGE) for maxval, most negative (-HUGE) for minval. */
/* We start with the most negative possible value for MAXLOC, and the most
positive possible value for MINLOC. The most negative possible value is
-HUGE for BT_REAL and (-HUGE - 1) for BT_INTEGER; the most positive
possible value is HUGE in both cases. */
if (op == GT_EXPR)
tmp = fold_build1 (NEGATE_EXPR, TREE_TYPE (tmp), tmp);
gfc_add_modify_expr (&se->pre, limit, tmp);
if (op == GT_EXPR && expr->ts.type == BT_INTEGER)
tmp = build2 (MINUS_EXPR, TREE_TYPE (tmp), tmp,
build_int_cst (type, 1));
/* Initialize the scalarizer. */
gfc_init_loopinfo (&loop);
gfc_add_ss_to_loop (&loop, arrayss);
@ -2143,9 +2150,17 @@ gfc_conv_intrinsic_minmaxval (gfc_se * se, gfc_expr * expr, int op)
gcc_unreachable ();
}
/* Most negative(-HUGE) for maxval, most positive (-HUGE) for minval. */
/* We start with the most negative possible value for MAXVAL, and the most
positive possible value for MINVAL. The most negative possible value is
-HUGE for BT_REAL and (-HUGE - 1) for BT_INTEGER; the most positive
possible value is HUGE in both cases. */
if (op == GT_EXPR)
tmp = fold_build1 (NEGATE_EXPR, TREE_TYPE (tmp), tmp);
if (op == GT_EXPR && expr->ts.type == BT_INTEGER)
tmp = build2 (MINUS_EXPR, TREE_TYPE (tmp), tmp,
build_int_cst (type, 1));
gfc_add_modify_expr (&se->pre, limit, tmp);
/* Walk the arguments. */

View File

@ -1,3 +1,8 @@
2007-02-09 Tobias Burnus <burnus@net-b.de>
PR fortran/30512
* gfortran.dg/maxlocval_1.f90: New test.
2007-02-09 Roger Sayle <roger@eyesopen.com>
* gcc.target/ia64/builtin_bswap-1.c: New test case.

View File

@ -0,0 +1,44 @@
! { dg-do run }
! Check that maxval uses for integers HUGE()-1.
! PR fortran/30512
program main
implicit none
integer(1) :: i1(3), a1(3:2)
integer(2) :: i2(3), a2(3:2)
integer(4) :: i4(3), a4(3:2)
integer(8) :: i8(3), a8(3:2)
integer(kind=4), allocatable :: a(:,:)
integer(kind=8), allocatable :: b(:,:)
logical :: msk(3)
msk = .false.
i1 = 1
i2 = 1
i4 = 1
i8 = 1
if(-huge(i1)-1_1 /= maxval(i1, msk)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(-huge(a1)-1_1 /= maxval(a1)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(-huge(i2)-1_2 /= maxval(i2, msk)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(-huge(a2)-1_2 /= maxval(a2)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(-huge(i4)-1_4 /= maxval(i4, msk)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(-huge(a4)-1_4 /= maxval(a4)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(-huge(i8)-1_4 /= maxval(i8, msk)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(-huge(a8)-1_4 /= maxval(a8)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
allocate (a(0:-1,1:1))
allocate (b(0:-1,1:1))
if(any(maxval(a,dim=1) /= -huge(a)-1_4)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(any(minval(a,dim=1) /= huge(a) )) call abort()
if(any(maxval(b,dim=1) /= -huge(b)-1_8)) call abort() ! { dg-warning "outside symmetric range implied by Standard Fortran" }
if(any(minval(b,dim=1) /= huge(b) )) call abort()
end program main

View File

@ -1,3 +1,30 @@
2007-02-09 Thomas Koenig <Thomas.Koenig@online.de>
Tobias Burnus <burnus@net-b.de>
PR fortran/30512
* m4/iparm.m4: Use HUGE-1 for most negative integer.
* generated/maxloc1_8_i4.c: Regenerate.
* generated/maxloc0_8_i8.c: Regenerate.
* generated/maxloc1_16_i4.c: Regenerate.
* generated/maxloc0_16_i8.c: Regenerate.
* generated/maxval_i4.c: Regenerate.
* generated/maxloc1_4_i8.c: Regenerate.
* generated/maxloc0_16_i16.c: Regenerate.
* generated/maxloc1_4_i16.c: Regenerate.
* generated/maxloc0_8_i16.c: Regenerate.
* generated/maxloc0_4_i4.c: Regenerate.
* generated/maxloc1_8_i8.c: Regenerate.
* generated/maxloc0_8_i4.c: Regenerate.
* generated/maxloc0_16_i4.c: Regenerate.
* generated/maxloc1_16_i8.c: Regenerate.
* generated/maxloc1_4_i4.c: Regenerate.
* generated/maxval_i8.c: Regenerate.
* generated/maxloc0_4_i16.c: Regenerate.
* generated/maxloc1_8_i16.c: Regenerate.
* generated/maxloc0_4_i8.c: Regenerate.
* generated/maxloc1_16_i16.c: Regenerate.
* generated/maxval_i16.c: Regenerate.
2007-02-04 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR fortran/30611

View File

@ -103,7 +103,7 @@ maxloc0_16_i16 (gfc_array_i16 * const restrict retarray,
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_16_i16 (gfc_array_i16 * const restrict retarray,
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_16_i4 (gfc_array_i16 * const restrict retarray,
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_16_i4 (gfc_array_i16 * const restrict retarray,
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_16_i8 (gfc_array_i16 * const restrict retarray,
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_16_i8 (gfc_array_i16 * const restrict retarray,
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_4_i16 (gfc_array_i4 * const restrict retarray,
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_4_i16 (gfc_array_i4 * const restrict retarray,
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_4_i4 (gfc_array_i4 * const restrict retarray,
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_4_i4 (gfc_array_i4 * const restrict retarray,
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_4_i8 (gfc_array_i4 * const restrict retarray,
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_4_i8 (gfc_array_i4 * const restrict retarray,
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_8_i16 (gfc_array_i8 * const restrict retarray,
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_8_i16 (gfc_array_i8 * const restrict retarray,
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_8_i4 (gfc_array_i8 * const restrict retarray,
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_8_i4 (gfc_array_i8 * const restrict retarray,
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
while (base)
{

View File

@ -103,7 +103,7 @@ maxloc0_8_i8 (gfc_array_i8 * const restrict retarray,
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
while (base)
{
@ -227,7 +227,7 @@ mmaxloc0_8_i8 (gfc_array_i8 * const restrict retarray,
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
while (base)
{

View File

@ -140,7 +140,7 @@ maxloc1_16_i16 (gfc_array_i16 * const restrict retarray,
{
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_16_i16 (gfc_array_i16 * const restrict retarray,
{
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_16_i4 (gfc_array_i16 * const restrict retarray,
{
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_16_i4 (gfc_array_i16 * const restrict retarray,
{
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_16_i8 (gfc_array_i16 * const restrict retarray,
{
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_16_i8 (gfc_array_i16 * const restrict retarray,
{
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_4_i16 (gfc_array_i4 * const restrict retarray,
{
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_4_i16 (gfc_array_i4 * const restrict retarray,
{
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
{
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_4_i4 (gfc_array_i4 * const restrict retarray,
{
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_4_i8 (gfc_array_i4 * const restrict retarray,
{
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_4_i8 (gfc_array_i4 * const restrict retarray,
{
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_8_i16 (gfc_array_i8 * const restrict retarray,
{
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_8_i16 (gfc_array_i8 * const restrict retarray,
{
GFC_INTEGER_16 maxval;
maxval = -GFC_INTEGER_16_HUGE;
maxval = (-GFC_INTEGER_16_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_8_i4 (gfc_array_i8 * const restrict retarray,
{
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_8_i4 (gfc_array_i8 * const restrict retarray,
{
GFC_INTEGER_4 maxval;
maxval = -GFC_INTEGER_4_HUGE;
maxval = (-GFC_INTEGER_4_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -140,7 +140,7 @@ maxloc1_8_i8 (gfc_array_i8 * const restrict retarray,
{
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
@ -315,7 +315,7 @@ mmaxloc1_8_i8 (gfc_array_i8 * const restrict retarray,
{
GFC_INTEGER_8 maxval;
maxval = -GFC_INTEGER_8_HUGE;
maxval = (-GFC_INTEGER_8_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;

View File

@ -138,9 +138,9 @@ maxval_i16 (gfc_array_i16 * const restrict retarray,
src = base;
{
result = -GFC_INTEGER_16_HUGE;
result = (-GFC_INTEGER_16_HUGE-1);
if (len <= 0)
*dest = -GFC_INTEGER_16_HUGE;
*dest = (-GFC_INTEGER_16_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta)
@ -308,9 +308,9 @@ mmaxval_i16 (gfc_array_i16 * const restrict retarray,
msrc = mbase;
{
result = -GFC_INTEGER_16_HUGE;
result = (-GFC_INTEGER_16_HUGE-1);
if (len <= 0)
*dest = -GFC_INTEGER_16_HUGE;
*dest = (-GFC_INTEGER_16_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
@ -404,7 +404,7 @@ smaxval_i16 (gfc_array_i16 * const restrict retarray,
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = -GFC_INTEGER_16_HUGE ;
dest[n * dstride] = (-GFC_INTEGER_16_HUGE-1) ;
}
#endif

View File

@ -138,9 +138,9 @@ maxval_i4 (gfc_array_i4 * const restrict retarray,
src = base;
{
result = -GFC_INTEGER_4_HUGE;
result = (-GFC_INTEGER_4_HUGE-1);
if (len <= 0)
*dest = -GFC_INTEGER_4_HUGE;
*dest = (-GFC_INTEGER_4_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta)
@ -308,9 +308,9 @@ mmaxval_i4 (gfc_array_i4 * const restrict retarray,
msrc = mbase;
{
result = -GFC_INTEGER_4_HUGE;
result = (-GFC_INTEGER_4_HUGE-1);
if (len <= 0)
*dest = -GFC_INTEGER_4_HUGE;
*dest = (-GFC_INTEGER_4_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
@ -404,7 +404,7 @@ smaxval_i4 (gfc_array_i4 * const restrict retarray,
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = -GFC_INTEGER_4_HUGE ;
dest[n * dstride] = (-GFC_INTEGER_4_HUGE-1) ;
}
#endif

View File

@ -138,9 +138,9 @@ maxval_i8 (gfc_array_i8 * const restrict retarray,
src = base;
{
result = -GFC_INTEGER_8_HUGE;
result = (-GFC_INTEGER_8_HUGE-1);
if (len <= 0)
*dest = -GFC_INTEGER_8_HUGE;
*dest = (-GFC_INTEGER_8_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta)
@ -308,9 +308,9 @@ mmaxval_i8 (gfc_array_i8 * const restrict retarray,
msrc = mbase;
{
result = -GFC_INTEGER_8_HUGE;
result = (-GFC_INTEGER_8_HUGE-1);
if (len <= 0)
*dest = -GFC_INTEGER_8_HUGE;
*dest = (-GFC_INTEGER_8_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
@ -404,7 +404,7 @@ smaxval_i8 (gfc_array_i8 * const restrict retarray,
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = -GFC_INTEGER_8_HUGE ;
dest[n * dstride] = (-GFC_INTEGER_8_HUGE-1) ;
}
#endif

View File

@ -28,6 +28,6 @@ define_type(rtype, rtype_tmp)dnl
define(rtype_qual,`_'rtype_kind)dnl
')dnl
define(atype_max, atype_name`_HUGE')dnl
define(atype_min, `-'atype_max)dnl
define(atype_min,ifelse(regexp(file, `_\(.\)[0-9]*\.c$', `\1'),`i',`(-'atype_max`-1)',`-'atype_max))dnl
define(name, regexp(regexp(file, `[^/]*$', `\&'), `^\([^_]*\)_', `\1'))dnl
define(rtype_ccode,ifelse(rtype_letter,`i',rtype_kind,rtype_code))dnl