From 702a738bdbd231eb88fb12c3383e6443c7a5fe73 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Tue, 19 Jan 2010 19:46:59 +0000 Subject: [PATCH] re PR fortran/42783 (Bogus Array bounds violation with optional array argument) 2010-01-19 Paul Thomas 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 PR fortran/42783 * gfortran.dg/bounds_check_15.f90 : New test. From-SVN: r156046 --- gcc/fortran/ChangeLog | 12 ++++++ gcc/fortran/trans-decl.c | 39 +++++++++++-------- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gfortran.dg/bounds_check_15.f90 | 33 ++++++++++++++++ 4 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/bounds_check_15.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d8e54e1ab9e..bbf484cd755 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,15 @@ +2010-01-19 Paul Thomas + + 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 PR fortran/42545 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 612c6f61296..062310af6af 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -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; + } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 58666a60a77..bdbed55c45b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-01-19 Paul Thomas + + PR fortran/42783 + * gfortran.dg/bounds_check_15.f90 : New test. + 2010-01-19 Michael Matz PR tree-optimization/41783 diff --git a/gcc/testsuite/gfortran.dg/bounds_check_15.f90 b/gcc/testsuite/gfortran.dg/bounds_check_15.f90 new file mode 100644 index 00000000000..947ffb2f4b4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bounds_check_15.f90 @@ -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 +! +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 -- 2.30.2