From 4a8108f0ab7310371123340e0181ff4afd84789e Mon Sep 17 00:00:00 2001 From: Mikael Morin Date: Fri, 8 May 2015 14:53:20 +0000 Subject: [PATCH] trans-array.c (gfc_walk_elemental_function_args): Don't skip the advance to the next dummy argument when... gcc/fortran/ * trans-array.c (gfc_walk_elemental_function_args): Don't skip the advance to the next dummy argument when skipping absent optional args. gcc/testsuite/ * gfortran.dg/elemental_optional_args_7.f90: New. From-SVN: r222913 --- gcc/fortran/ChangeLog | 6 +++ gcc/fortran/trans-array.c | 3 +- gcc/testsuite/ChangeLog | 4 ++ .../gfortran.dg/elemental_optional_args_7.f90 | 37 +++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/elemental_optional_args_7.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 67f9e097e47..1091b187d06 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2015-05-08 Mikael Morin + + * trans-array.c (gfc_walk_elemental_function_args): + Don't skip the advance to the next dummy argument when skipping + absent optional args. + 2015-05-05 David Malcolm * expr.c (check_inquiry): Fix indentation so that it reflects the diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index a17f4314d47..00334b13191 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -9092,7 +9092,7 @@ gfc_walk_elemental_function_args (gfc_ss * ss, gfc_actual_arglist *arg, for (; arg; arg = arg->next) { if (!arg->expr || arg->expr->expr_type == EXPR_NULL) - continue; + goto loop_continue; newss = gfc_walk_subexpr (head, arg->expr); if (newss == head) @@ -9122,6 +9122,7 @@ gfc_walk_elemental_function_args (gfc_ss * ss, gfc_actual_arglist *arg, tail = tail->next; } +loop_continue: if (dummy_arg != NULL) dummy_arg = dummy_arg->next; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e71b8e043d7..c904070b6ac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-05-08 Mikael Morin + + * gfortran.dg/elemental_optional_args_7.f90: New. + 2015-05-08 Alan Lawrence * gcc.target/aarch64/singleton_intrinsics_1.c: Generalize regex to diff --git a/gcc/testsuite/gfortran.dg/elemental_optional_args_7.f90 b/gcc/testsuite/gfortran.dg/elemental_optional_args_7.f90 new file mode 100644 index 00000000000..8d366c37838 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/elemental_optional_args_7.f90 @@ -0,0 +1,37 @@ +! { dg-do run } +! +! The handling of scalar optional arguments passed to elemental procedure +! did not keep actual arguments and dummy arguments synchronized while +! walking them in gfc_walk_elemental_function_args, leading to a +! null pointer dereference in the generated code. +! + implicit none + + integer, parameter :: n = 3 + + call do_test + +contains + + elemental function five(nonopt1, opt1, nonopt2, opt2) + integer, intent(in), optional :: opt1, opt2 + integer, intent(in) :: nonopt1, nonopt2 + integer :: five + + if (.not. present(opt1) .and. .not. present(opt2)) then + five = 5 + else + five = -7 + end if + end function five + + subroutine do_test(opt) + integer, optional :: opt + integer :: i = -1, a(n) = (/ (i, i=1,n) /) + integer :: b(n) + + b = five(a, nonopt2=i, opt2=opt) + if (any(b /= 5)) call abort + end subroutine do_test + +end -- 2.30.2