aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2010-01-19 19:46:59 +0000
committerPaul Thomas <pault@gcc.gnu.org>2010-01-19 19:46:59 +0000
commit4c737971c17e2b91762b3e3f7ba122860019d69f (patch)
tree59f59cd796bef5a176ee21db239f922538ac3c28
parentdcc493895313fb7237edb0c71be115ff0d36cdcb (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@156046 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/fortran/ChangeLog12
-rw-r--r--gcc/fortran/trans-decl.c39
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/bounds_check_15.f9033
4 files changed, 73 insertions, 16 deletions
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 <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
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 <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
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 <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