Commit 18fe404f by Thomas Koenig

re PR fortran/30814 (non-conforming array sizes in PACK should raise an error)

2007-07-24  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/30814
	* trans-decl.c (generate_function_code):  Add argument
	for flag_bounds_check to the array for set_options.
	* invoke.texi:  Mention that some checks require
	-fbounds-check to be set during compilation of the
	main program.

2007-07-24  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/30814
	* libgfortran.h:  Add bounds_check to compile_options_t.
	* runtime/compile_options.c (set_options):  Add handling
	of compile_options.bounds_check.
	* intrinsics/pack_generic.c (pack_internal):  Also determine
	the number of elements if compile_options.bounds_check is
	true.  Raise runtime error if a different array shape is
	detected.

2007-07-24  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/30814
	* gfortran.dg/pack_bounds_1.f90:  New test case.

From-SVN: r126866
parent bf3900bf
2007-07-24 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/30814
* libgfortran.h: Add bounds_check to compile_options_t.
* runtime/compile_options.c (set_options): Add handling
of compile_options.bounds_check.
* intrinsics/pack_generic.c (pack_internal): Also determine
the number of elements if compile_options.bounds_check is
true. Raise runtime error if a different array shape is
detected.
2007-07-23 Daniel Franke <franke.daniel@gmail.com> 2007-07-23 Daniel Franke <franke.daniel@gmail.com>
PR fortran/25104 PR fortran/25104
......
...@@ -828,6 +828,9 @@ and against the declared minimum and maximum values. It also ...@@ -828,6 +828,9 @@ and against the declared minimum and maximum values. It also
checks array indices for assumed and deferred checks array indices for assumed and deferred
shape arrays against the actual allocated bounds. shape arrays against the actual allocated bounds.
Some checks require that @option{-fbounds-check} is set for
the compilation of the main probram.
In the future this may also include other forms of checking, e.g., checking In the future this may also include other forms of checking, e.g., checking
substring references. substring references.
......
...@@ -3191,9 +3191,13 @@ gfc_generate_function_code (gfc_namespace * ns) ...@@ -3191,9 +3191,13 @@ gfc_generate_function_code (gfc_namespace * ns)
build_int_cst (gfc_c_int_type_node, build_int_cst (gfc_c_int_type_node,
gfc_option.flag_sign_zero), array); gfc_option.flag_sign_zero), array);
array = tree_cons (NULL_TREE,
build_int_cst (gfc_c_int_type_node,
flag_bounds_check), array);
array_type = build_array_type (gfc_c_int_type_node, array_type = build_array_type (gfc_c_int_type_node,
build_index_type (build_int_cst (NULL_TREE, build_index_type (build_int_cst (NULL_TREE,
5))); 6)));
array = build_constructor_from_list (array_type, nreverse (array)); array = build_constructor_from_list (array_type, nreverse (array));
TREE_CONSTANT (array) = 1; TREE_CONSTANT (array) = 1;
TREE_INVARIANT (array) = 1; TREE_INVARIANT (array) = 1;
...@@ -3209,7 +3213,7 @@ gfc_generate_function_code (gfc_namespace * ns) ...@@ -3209,7 +3213,7 @@ gfc_generate_function_code (gfc_namespace * ns)
var = gfc_build_addr_expr (pvoid_type_node, var); var = gfc_build_addr_expr (pvoid_type_node, var);
tmp = build_call_expr (gfor_fndecl_set_options, 2, tmp = build_call_expr (gfor_fndecl_set_options, 2,
build_int_cst (gfc_c_int_type_node, 6), var); build_int_cst (gfc_c_int_type_node, 7), var);
gfc_add_expr_to_block (&body, tmp); gfc_add_expr_to_block (&body, tmp);
} }
......
2007-07-24 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/30814
* gfortran.dg/pack_bounds_1.f90: New test case.
2007-07-23 Daniel Franke <franke.daniel@gmail.com> 2007-07-23 Daniel Franke <franke.daniel@gmail.com>
PR fortran/31639 PR fortran/31639
! { dg-do run }
! { dg-options "-fbounds-check" }
! { dg-shouldfail "Incorrect extent in return value of PACK intrinsic" }
! PR 30814 - a bounds error with pack was not caught.
program main
integer :: a(2,2), b(5)
a = reshape((/ 1, -1, 1, -1 /), shape(a))
b = pack(a, a /= 0)
end program main
! { dg-output "Fortran runtime error: Incorrect extent in return value of PACK intrinsic" }
2007-07-24 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/30814
* libgfortran.h: Add bounds_check to compile_options_t.
* runtime/compile_options.c (set_options): Add handling
of compile_options.bounds_check.
* intrinsics/pack_generic.c (pack_internal): Also determine
the number of elements if compile_options.bounds_check is
true. Raise runtime error if a different array shape is
detected.
2007-07-23 Christopher D. Rickett <crickett@lanl.gov> 2007-07-23 Christopher D. Rickett <crickett@lanl.gov>
PR fortran/32600 PR fortran/32600
......
...@@ -97,6 +97,7 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array, ...@@ -97,6 +97,7 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array,
index_type n; index_type n;
index_type dim; index_type dim;
index_type nelem; index_type nelem;
index_type total;
dim = GFC_DESCRIPTOR_RANK (array); dim = GFC_DESCRIPTOR_RANK (array);
zero_sized = 0; zero_sized = 0;
...@@ -127,10 +128,10 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array, ...@@ -127,10 +128,10 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array,
mptr = GFOR_POINTER_L8_TO_L4 (mptr); mptr = GFOR_POINTER_L8_TO_L4 (mptr);
} }
if (ret->data == NULL) if (ret->data == NULL || compile_options.bounds_check)
{ {
/* Allocate the memory for the result. */ /* Count the elements, either for allocating memory or
int total; for bounds checking. */
if (vector != NULL) if (vector != NULL)
{ {
...@@ -196,6 +197,8 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array, ...@@ -196,6 +197,8 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array,
} }
} }
if (ret->data == NULL)
{
/* Setup the array descriptor. */ /* Setup the array descriptor. */
ret->dim[0].lbound = 0; ret->dim[0].lbound = 0;
ret->dim[0].ubound = total - 1; ret->dim[0].ubound = total - 1;
...@@ -211,6 +214,14 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array, ...@@ -211,6 +214,14 @@ pack_internal (gfc_array_char *ret, const gfc_array_char *array,
else else
ret->data = internal_malloc_size (size * total); ret->data = internal_malloc_size (size * total);
} }
else
{
/* We come here because of range checking. */
if (total != ret->dim[0].ubound + 1 - ret->dim[0].lbound)
runtime_error ("Incorrect extent in return value of"
" PACK intrinsic");
}
}
rstride0 = ret->dim[0].stride * size; rstride0 = ret->dim[0].stride * size;
if (rstride0 == 0) if (rstride0 == 0)
......
...@@ -54,6 +54,8 @@ set_options (int num, int options[]) ...@@ -54,6 +54,8 @@ set_options (int num, int options[])
compile_options.backtrace = options[4]; compile_options.backtrace = options[4];
if (num >= 6) if (num >= 6)
compile_options.sign_zero = options[5]; compile_options.sign_zero = options[5];
if (num >= 7)
compile_options.bounds_check = options[6];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment