This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR31205 - aliased operator assignment produces wrong result


:ADDPATCH fortran:

The first version of this patch was posted on
http://gcc.gnu.org/ml/fortran/2007-06/msg00526.html. FX reviewed and
OK'd it.  I was about to commit, when I thought that this was the sort
of patch that would break cp2k and this turned out to be true.....
Diagnosing the problem turned out to be a real head-ache but the fix
was easy and entirely associated with gfc_get_parentheses and its
resolution.  Look at the differences in matchexp.c and resolve.c
between the two patches.

Since the original posting, Tobias Burnus provoked me to go back to
some of the remaining bugs in the iso_varying_string testsuite by
Lawrie Schonfeld.  This patch fixes it and has resulted in a second
testcase (PR32842).

As I wrote originally, neither aliased lhs and rhs in operator
assignments, nor INTENT(IN) actual arguments, aliased with an
INTENT(OUT) argument, would produce the correct result, if the
argument was a derived type with a default initializer.

The steps taken to fix this problem were:

(i) Generate a temporary for the rhs/INTENT(IN), using
gfc_get_parentheses.  This required a bit of work on this function to
checking for references with character expressions.  I believe that
this will be unnecessary when I complete the character patch ("next
week's task" Hah! I'm stuck on this one too but at the level of
weeding out old kludges that do not seem to want to be weeded out...)
and will update accordingly.

(ii) Remove the initialization of derived types with a default
initializer from the caller to the callee.  The reasons for doing this
are discussed in the PR.  It has a gratifying effect on passing
derived types with allocatable components, in that the amount of
generated code goes down (see alloc_comp_basics_1.f90).

Note (i) involved what I believe is a misinterpretation of the
standard - see the comment and the relevant paragraph in the standard
(7.1.7.2).  This version of the patch actually implements the
standard, up to the problem with characters, by making all expressions
in parentheses "data entities".

The first testcase is the reporter's for the original PR and the
second is described above.

This version allows compilation and execution of cp2k... phew!

Bootstrapped and regtested on x86_ia64/FC5 - OK for trunk?

Paul

2007-07-23 Paul Thomas <pault@gcc.gnu.org>


PR fortran/31205 PR fortran/32842 * trans-expr.c (gfc_conv_function_call): Remove the default initialization of intent(out) derived types. * symbol.c (gfc_lval_expr_from_sym): New function. * matchexp.c (gfc_get_parentheses): Return argument, if it is character and posseses a ref. * gfortran.h : Add prototype for gfc_lval_expr_from_sym. * resolve.c (has_default_initializer): Move higher up in file. (resolve_code): On detecting an interface assignment, check if the rhs and the lhs are the same symbol. If this is so, enclose the rhs in parenetheses to generate a temporary and prevent any possible aliasing. (apply_default_init): Remove code making the lval and call gfc_lval_expr_from_sym instead. (resolve_operator): Give a parentheses expression a type- spec if it has no type. * trans-decl.c (gfc_trans_deferred_vars): Apply the a default initializer, if any, to an intent(out) derived type, using gfc_lval_expr_from_sym and gfc_trans_assignment. Check if the dummy is present.


2007-07-23 Paul Thomas <pault@gcc.gnu.org>



PR fortran/31205 * gfortran.dg/alloc_comp_basics_1.f90 : Restore number of "deallocates" to 24, since patch has code rid of much spurious code. * gfortran.dg/interface_assignment_1.f90 : New test.

	PR fortran/32842
	* gfortran.dg/interface_assignment_2.f90 : New test.

Attachment: pr31205.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]