This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR fortran/31538
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 16 Apr 2010 15:26:06 -0700
- Subject: [PATCH] Fix PR fortran/31538
The attach patch fixes PF fortran/31538. It has been regression
tested on i686-*-freebsd. Briefly, I've updated the error from
a not so helpful
laptop:kargl[205] gfc4x -o z -fcheck=bounds g.f90
laptop:kargl[206] ./z
At line 9 of file g.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'f'
to
laptop:kargl[211] gfc4x -o z -fcheck=bounds g.f90
laptop:kargl[212] ./z
At line 9 of file g.f90
Fortran runtime error: Dimension 1 of array 'f' has extent 5 instead of 6
laptop:kargl[213]
for the program in comment #5 of the PR.
integer :: a(-4:1), b(0:4)
b = 5
i = -4
a(i:1) = f(b)
contains
function f(x)
integer :: x(:),f(size(x))
f = x
end function
end
Changing the error then showed that gfc_msg_bounds in trans.c
was only used in one place, so I've eliminated this variable.
During the elimination I slightly improved the error message
where gfc_msg_bounds was used, which necessitated updating the
testcases.
2010-04-16 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/31538
* gfortran.dg/bounds_check_fail_4.f90: Adjust error message.
* gfortran.dg/bounds_check_fail_3.f90: Ditto.
2010-04-16 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/31538
* fortran/trans-array.c (gfc_conv_ss_startstride): Remove the use of
gfc_msg_bounds by using 'Array bound mismatch' directly.
(gfc_trans_dummy_array_bias): Remove the use of gfc_msg_bounds. Reword
error message to include the mismatch in the extent of array bound.
* fortran/trans.c: Remove gfc_msg_bounds. It is only used in one place.
* fortran/trans.h: Remove extern definition of gfc_msg_bounds.
OK for trunk?
--
Steve
Index: testsuite/gfortran.dg/bounds_check_fail_4.f90
===================================================================
--- testsuite/gfortran.dg/bounds_check_fail_4.f90 (revision 158451)
+++ testsuite/gfortran.dg/bounds_check_fail_4.f90 (working copy)
@@ -9,4 +9,4 @@
if (any(x /= (/ 5, 2, 3, 6, 5, 6, 7, 8, 9, 10 /))) call abort()
x(8:1:m) = x(1:3) + x(5:2:n)
end
-! { dg-output "line 10 .* bound mismatch, .* dimension 1 .* array \'x\' \\\(2/3\\\)" }
+! { dg-output "line 10 .* bound mismatch .* dimension 1 .* array \'x\' \\\(2/3\\\)" }
Index: testsuite/gfortran.dg/bounds_check_fail_3.f90
===================================================================
--- testsuite/gfortran.dg/bounds_check_fail_3.f90 (revision 158451)
+++ testsuite/gfortran.dg/bounds_check_fail_3.f90 (working copy)
@@ -9,4 +9,4 @@
if (any(x /= (/ 2, 2, 3, 4, 5, 6, 6, 8, 9, 10 /))) call abort()
x(8:1:m) = x(5:2:n)
end
-! { dg-output "line 10 .* bound mismatch, .* dimension 1 .* array \'x\' \\\(3/2\\\)" }
+! { dg-output "line 10 .* bound mismatch .* dimension 1 .* array \'x\' \\\(3/2\\\)" }
Index: fortran/trans-array.c
===================================================================
--- fortran/trans-array.c (revision 158451)
+++ fortran/trans-array.c (working copy)
@@ -3365,13 +3365,15 @@ gfc_conv_ss_startstride (gfc_loopinfo *
if (size[n])
{
tmp3 = fold_build2 (NE_EXPR, boolean_type_node, tmp, size[n]);
- asprintf (&msg, "%s, size mismatch for dimension %d "
- "of array '%s' (%%ld/%%ld)", gfc_msg_bounds,
+ asprintf (&msg, "Array bound mismatch for dimension %d "
+ "of array '%s' (%%ld/%%ld)",
info->dim[n]+1, ss->expr->symtree->name);
+
gfc_trans_runtime_check (true, false, tmp3, &inner,
&ss->expr->where, msg,
fold_convert (long_integer_type_node, tmp),
fold_convert (long_integer_type_node, size[n]));
+
gfc_free (msg);
}
else
@@ -4632,15 +4634,26 @@ gfc_trans_dummy_array_bias (gfc_symbol *
{
/* Check (ubound(a) - lbound(a) == ubound(b) - lbound(b)). */
char * msg;
+ tree temp;
+
+ temp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
+ ubound, lbound);
+ temp = fold_build2 (PLUS_EXPR, gfc_array_index_type,
+ gfc_index_one_node, temp);
- tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
- ubound, lbound);
stride2 = fold_build2 (MINUS_EXPR, gfc_array_index_type,
dubound, dlbound);
- tmp = fold_build2 (NE_EXPR, gfc_array_index_type, tmp, stride2);
- asprintf (&msg, "%s for dimension %d of array '%s'",
- gfc_msg_bounds, n+1, sym->name);
- gfc_trans_runtime_check (true, false, tmp, &block, &loc, msg);
+ stride2 = fold_build2 (PLUS_EXPR, gfc_array_index_type,
+ gfc_index_one_node, stride2);
+
+ tmp = fold_build2 (NE_EXPR, gfc_array_index_type, temp, stride2);
+ asprintf (&msg, "Dimension %d of array '%s' has extent %%ld instead of %%ld",
+ n+1, sym->name);
+
+ gfc_trans_runtime_check (true, false, tmp, &block, &loc, msg,
+ fold_convert (long_integer_type_node, temp),
+ fold_convert (long_integer_type_node, stride2));
+
gfc_free (msg);
}
}
Index: fortran/trans.c
===================================================================
--- fortran/trans.c (revision 158451)
+++ fortran/trans.c (working copy)
@@ -47,7 +47,6 @@ along with GCC; see the file COPYING3.
static gfc_file *gfc_current_backend_file;
-const char gfc_msg_bounds[] = N_("Array bound mismatch");
const char gfc_msg_fault[] = N_("Array reference out of bounds");
const char gfc_msg_wrong_return[] = N_("Incorrect function return value");
Index: fortran/trans.h
===================================================================
--- fortran/trans.h (revision 158451)
+++ fortran/trans.h (working copy)
@@ -773,7 +773,6 @@ void gfc_apply_interface_mapping (gfc_in
/* Standard error messages used in all the trans-*.c files. */
-extern const char gfc_msg_bounds[];
extern const char gfc_msg_fault[];
extern const char gfc_msg_wrong_return[];