re PR fortran/42783 (Bogus Array bounds violation with optional array argument)

2010-01-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/42783
	* trans-decl.c (add_argument_checking): Do not use the backend
	decl directly to test for the presence of an optional dummy
	argument.  Use gfc_conv_expr_present, remembering to set the
	symbol referenced.

	PR fortran/42772
	* trans-decl.c (gfc_generate_function_code): Small white space
	changes. If 'recurcheckvar' is NULL do not try to reset it.

2010-01-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/42783
	* gfortran.dg/bounds_check_15.f90 : New test.

From-SVN: r156046
This commit is contained in:
Paul Thomas 2010-01-19 19:46:59 +00:00
parent a4f3bbc6e3
commit 702a738bdb
4 changed files with 73 additions and 16 deletions

View File

@ -1,3 +1,15 @@
2010-01-19 Paul Thomas <pault@gcc.gnu.org>
PR fortran/42783
* trans-decl.c (add_argument_checking): Do not use the backend
decl directly to test for the presence of an optional dummy
argument. Use gfc_conv_expr_present, remembering to set the
symbol referenced.
PR fortran/42772
* trans-decl.c (gfc_generate_function_code): Small white space
changes. If 'recurcheckvar' is NULL do not try to reset it.
2010-01-19 Janus Weil <janus@gcc.gnu.org>
PR fortran/42545

View File

@ -3999,8 +3999,9 @@ add_argument_checking (stmtblock_t *block, gfc_symbol *sym)
cl->passed_length,
fold_convert (gfc_charlen_type_node,
integer_zero_node));
not_absent = fold_build2 (NE_EXPR, boolean_type_node,
fsym->backend_decl, null_pointer_node);
/* The symbol needs to be referenced for gfc_get_symbol_decl. */
fsym->attr.referenced = 1;
not_absent = gfc_conv_expr_present (fsym);
absent_failed = fold_build2 (TRUTH_OR_EXPR, boolean_type_node,
not_0length, not_absent);
@ -4256,7 +4257,7 @@ gfc_generate_function_code (gfc_namespace * ns)
stmtblock_t block;
stmtblock_t body;
tree result;
tree recurcheckvar = NULL;
tree recurcheckvar = NULL_TREE;
gfc_symbol *sym;
int rank;
bool is_recursive;
@ -4330,8 +4331,9 @@ gfc_generate_function_code (gfc_namespace * ns)
is_recursive = sym->attr.recursive
|| (sym->attr.entry_master
&& sym->ns->entries->sym->attr.recursive);
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION) && !is_recursive
&& !gfc_option.flag_recursive)
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
&& !is_recursive
&& !gfc_option.flag_recursive)
{
char * msg;
@ -4348,7 +4350,7 @@ gfc_generate_function_code (gfc_namespace * ns)
}
if (TREE_TYPE (DECL_RESULT (fndecl)) != void_type_node
&& sym->attr.subroutine)
&& sym->attr.subroutine)
{
tree alternate_return;
alternate_return = gfc_get_fake_result_decl (sym, 0);
@ -4395,8 +4397,9 @@ gfc_generate_function_code (gfc_namespace * ns)
else
result = sym->result->backend_decl;
if (result != NULL_TREE && sym->attr.function
&& !sym->attr.pointer)
if (result != NULL_TREE
&& sym->attr.function
&& !sym->attr.pointer)
{
if (sym->ts.type == BT_DERIVED
&& sym->ts.u.derived->attr.alloc_comp)
@ -4413,8 +4416,10 @@ gfc_generate_function_code (gfc_namespace * ns)
gfc_add_expr_to_block (&block, tmp);
/* Reset recursion-check variable. */
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION) && !is_recursive
&& !gfc_option.flag_openmp)
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
&& !is_recursive
&& !gfc_option.flag_openmp
&& recurcheckvar != NULL_TREE)
{
gfc_add_modify (&block, recurcheckvar, boolean_false_node);
recurcheckvar = NULL;
@ -4445,12 +4450,14 @@ gfc_generate_function_code (gfc_namespace * ns)
{
gfc_add_expr_to_block (&block, tmp);
/* Reset recursion-check variable. */
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION) && !is_recursive
&& !gfc_option.flag_openmp)
{
gfc_add_modify (&block, recurcheckvar, boolean_false_node);
recurcheckvar = NULL;
}
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
&& !is_recursive
&& !gfc_option.flag_openmp
&& recurcheckvar != NULL_TREE)
{
gfc_add_modify (&block, recurcheckvar, boolean_false_node);
recurcheckvar = NULL_TREE;
}
}

View File

@ -1,3 +1,8 @@
2010-01-19 Paul Thomas <pault@gcc.gnu.org>
PR fortran/42783
* gfortran.dg/bounds_check_15.f90 : New test.
2010-01-19 Michael Matz <matz@suse.de>
PR tree-optimization/41783

View File

@ -0,0 +1,33 @@
! { dg-do run }
! { dg-options "-fbounds-check" }
! Test the fix for PR42783, in which a bogus array bounds violation
! with missing optional array argument.
!
! Contributed by Harald Anlauf <anlauf@gmx.de>
!
program gfcbug99
implicit none
character(len=8), parameter :: mnem_list(2) = "A"
call foo (mnem_list) ! This call succeeds
call foo () ! This call fails
contains
subroutine foo (mnem_list)
character(len=8) ,intent(in) ,optional :: mnem_list(:)
integer :: i,j
character(len=256) :: ml
ml = ''
j = 0
if (present (mnem_list)) then
do i = 1, size (mnem_list)
if (mnem_list(i) /= "") then
j = j + 1
if (j > len (ml)/8) call abort ()
ml((j-1)*8+1:(j-1)*8+8) = mnem_list(i)
end if
end do
end if
if (j > 0) print *, trim (ml(1:8))
end subroutine foo
end program gfcbug99