[Patch, Fortran] PR41629: [OOP] gimplification error on valid code

Janus Weil janus@gcc.gnu.org
Thu Oct 8 18:41:00 GMT 2009


2009/10/8 Janus Weil <janus@gcc.gnu.org>:
> Hi all,
>
> the attached patch fixes an issue with the current OOP implementation,
> which looks harmless at first but turned out to be rather tricky. The
> problem is that we call encapsulate_class_symbol too early. This
> routine constructs a CLASS container type, which contains the declared
> type as 'data' component and an integer 'vindex', and needs to know
> all the attributes of the symbol to do that.
>
> Currently we call it already when parsing. This is ok for CLASS-valued
> components, but for plain CLASS variables one can have cases like
> this:
>
>  class(t1) :: x
>  pointer :: x
>
> Here we already construct the CLASS container after reading the first
> line, and so the pointer attribute comes too late and mixes things up,
> which ultimately leads to a gimplification error in the test case.
>
> The only clean solution I can see is to construct the CLASS container
> at resolution stage, where all attributes are known. However, this is
> a bit tricky, as all CLASS variables then change their type at
> resolution stage, and we have to take special care of this.
>
> Example: gfc_type_compatible is called both at parsing and resolution
> stage, and so I had to modify it a bit, so that it can work in both
> situations (at first a class variable has its declared type, later it
> is transformed into a class container type).
>
> Another example: All component references of CLASS variables have the
> wrong parent symbol (i.e. the type itself instead of the class
> container), and this needs to be fixed at resolution stage (in
> gfc_variable_attr).
>
> I think I have managed to sort out all regressions by now (which was
> not quite easy). I'm just running another regtest to make sure.
>
> Ok for trunk? (I will add a ChangeLog and the test case from the PR)

Here's the test case and ChangeLog.

Cheers,
Janus


2009-10-08  Janus Weil  <janus@gcc.gnu.org>

	* decl.c (encapsulate_class_symbol): Make non-static, add argument
	'where' and move an error check inside.
	(build_sym): Remove call to 'encapsulate_class_symbol'.
	(build_struct): Move error check before the call to
	'encapsulate_class_symbol'.
	* gfortran.h (encapsulate_class_symbol): New prototype.
	* match.c (gfc_match_allocate,gfc_match_deallocate): Remove unneeded
	special case code for CLASS variables.
	(gfc_match_select_type): Pop namespace on error.
	* primary.c (gfc_match_varspec): Remove unneeded special case code for
	CLASS variables.
	(gfc_variable_attr): Update typespec for CLASS variables.
	* resolve.c (resolve_ordinary_assign): Move a variable to a local block.
	(resolve_fl_variable_derived): Check if proc_name is present.
	Move error checks for CLASS variable somewhere else.
	(resolve_typebound_procedure): Resolve pass-arg before doing checks.
	(resolve_fl_derived): Resolve pass-arg before doing checks. Move error
	check somewhere else.
	(resolve_symbol): Move error check here and call
	'encapsulate_class_symbol'.
	* symbol.c (gfc_type_compatible): Make it more flexible.


2009-10-08  Janus Weil  <janus@gcc.gnu.org>

	* gfortran.dg/class_4.f03: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: class_4.f03
Type: application/octet-stream
Size: 286 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20091008/b15bfd02/attachment.obj>


More information about the Gcc-patches mailing list