On 09.01.2012 15:45, Tobias Burnus wrote:
On 01/09/2012 03:34 PM, Mikael Morin wrote:
The issue is that the code handling NULL() doesn't consume the gfc_ss
struct created for it. Your fix, which advances to the next one anyway
would work just well, but I think it is slightly cleaner to not create
the struct in the first place, as it is unused.
I'm currently regtesting the following patch. The testcase is the same
as your. OK for 4.7/4.6?
OK.
For the test case, either take mine or don't forget to enable all "if()
abort"s and to change in the last "! print *,a" the "a" into a "b".
+ if (!arg->expr
+ || arg->expr->expr_type == EXPR_NULL)
continue;
(I'd prefer to have no line break before the "||".)
Tobias
Thanks. Committed.
Mikael
Index: testsuite/gfortran.dg/optional_absent_2.f90
===================================================================
--- testsuite/gfortran.dg/optional_absent_2.f90 (révision 0)
+++ testsuite/gfortran.dg/optional_absent_2.f90 (révision 183024)
@@ -0,0 +1,53 @@
+! { dg-do run }
+!
+! PR fortran/51758
+!
+! Contributed by Mikael Morin
+!
+! Check whether passing NULL() to an elemental procedure works,
+! where NULL() denotes an absent optional argument.
+!
+program p
+
+ integer :: a(2)
+ integer :: b
+
+ a = 0
+ a = foo((/ 1, 1 /), null())
+! print *, a
+ if (any(a /= 2)) call abort
+
+ a = 0
+ a = bar((/ 1, 1 /), null())
+! print *, a
+ if (any(a /= 2)) call abort
+
+ b = 0
+ b = bar(1, null())
+! print *, b
+ if (b /= 2) call abort
+
+contains
+
+ function foo(a, b)
+ integer :: a(:)
+ integer, optional :: b(:)
+ integer :: foo(size(a))
+
+ if (present(b)) call abort
+
+ foo = 2
+ end function foo
+
+ elemental function bar(a, b)
+ integer, intent(in) :: a
+ integer, intent(in), optional :: b
+ integer :: bar
+
+ bar = 2
+
+ if (present(b)) bar = 1
+
+ end function bar
+
+end program p
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog (révision 183023)
+++ testsuite/ChangeLog (révision 183024)
@@ -1,5 +1,10 @@
2012-01-09 Tobias Burnus <bur...@net-b.de>
+ PR fortran/51758
+ * gfortran.dg/optional_absent_2.f90: New.
+
+2012-01-09 Tobias Burnus <bur...@net-b.de>
+
PR fortran/51578
* gfortran.dg/use_17.f90: New.
Index: fortran/trans-array.c
===================================================================
--- fortran/trans-array.c (révision 183023)
+++ fortran/trans-array.c (révision 183024)
@@ -8369,7 +8369,7 @@ gfc_walk_elemental_function_args (gfc_ss * ss, gfc
scalar = 1;
for (; arg; arg = arg->next)
{
- if (!arg->expr)
+ if (!arg->expr || arg->expr->expr_type == EXPR_NULL)
continue;
newss = gfc_walk_subexpr (head, arg->expr);
Index: fortran/ChangeLog
===================================================================
--- fortran/ChangeLog (révision 183023)
+++ fortran/ChangeLog (révision 183024)
@@ -1,3 +1,9 @@
+2012-01-09 Mikael Morin <mik...@gcc.gnu.org>
+
+ PR fortran/51758
+ * trans-array.c (gfc_walk_elemental_function_args):
+ Skip over NULL() actual arguments.
+
2012-01-09 Tobias Burnus <bur...@net-b.de>
* gfortran.texi: Bump copyright year.