[Patch, fortran] PR fortran/50981 segmentation fault when trying to access absent elemental actual arg

Mikael Morin mikael.morin@sfr.fr
Sat Dec 31 17:26:00 GMT 2011


Hello, as promised, here is a fix for pr50981.

Currently, for a call to an elemental procedure, every scalar actual
argument is evaluated before the loop containing the function call.
The bug is, we can't evaluate the actual argument if it is a reference
to an absent optional dummy argument, as it will result in a NULL
pointer dereference.  We must pass the reference directly in that case.

To fix this, the call to gfc_conv_expr in gfc_add_loop_ss_code, must be
changed to a call to gfc_conv_expr_reference.  Such a change is
basically a revert of PR43841's fix, so we are back with a missed
optimization bug.  To avoid this we have to do the change only when it
is necessary, i.e. when the dummy argument is optional and the actual
argument is a reference to an optional dummy.  This information is
not available in gfc_add_loop_ss_code, so I make for it a new field
can_be_null_ref in the gfc_ss_info struct: this is the second patch.
Then, the third patch is about setting that field: as the dummy argument
information isn't either available in gfc_walk_elemental_function_args,
a new argument, proc_expr, is added, which holds the reference to the
procedure.  It is of type gfc_expr* so that it can handle direct calls
and type-bound calls equally well.

The first patch is for consistency: gfc_conv_expr should return values,
not references, so the address taking is moved where it is
actually requested (in gfc_conv_expr_reference).

Regression tested on x86_64-unknown-linux-gnu. OK for 4.7/4.6/4.5[/4.4] ?

Mikael.

PS: Greetings for the new year.






-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr50981_1.CL
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr50981_1.diff
Type: text/x-patch
Size: 862 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr50981_2.CL
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment-0001.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr50981_2.diff
Type: text/x-patch
Size: 2793 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment-0001.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr50981_3.CL
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment-0002.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr50981_3.diff
Type: text/x-patch
Size: 4374 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment-0002.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr50981_test.CL
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment-0003.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: elemental_optional_args_2.f90
Type: text/x-fortran
Size: 1857 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111231/403ca23c/attachment-0003.bin>


More information about the Fortran mailing list