[patch] for PR 19362

Paul Brook paul@codesourcery.com
Thu Jul 21 01:25:00 GMT 2005


On Thursday 13 January 2005 22:54, Zdenek Dvorak wrote:
> Hello,
>
> while the two types t0 in the testcase are identical from the point of
> view of fortran (I hope, I am no fortran expert), they are represented
> as two distinct types internally.  This causes ICE in
> gfc_trans_scalar_assign when emitting the assignment and casting rhs of
> the assignment to lhs, since fold_convert cannot convert aggregate
> types.
>
> To fix the problem, the patch makes the function to add
> VIEW_CONVERT_EXPR in case the assigned types differ and
> they are aggregates.
>
> Bootstrapped & regtested on i686.
>
> Zdenek
>
> 	PR fortran/19362
> 	* trans-expr.c (gfc_trans_scalar_assign): Add VIEW_CONVERT_EXPR
> 	for aggregates if the types differ.

I'd rather not. I suspect this is just papering over the bug.
Can we interchange (fortran) pointers to type(T0) and type(T1) ? Do the 
optimisers know that they alias.

The original example in the PR is illegal. BAR and BAZ have different types.
The exception in Section 4.4.2 for objects of derived type with the same name 
only applies to objects defined in different scoping units.

It appears that at least some commercial compilers do accept this code, so we 
may wish to accept it as an extension. If so we have two options:
- Treat the two types as the same type. This could cause problems with user 
defined operators involving the two types. The frontend needs to either 
replace all occurrences of one type with the other, or tell the back tree 
generation routines that they are the same.
- Leave the two types as distinct types. Allow assignmend between two 
"similar" types as an extension. The frontend should insert an explicit 
conversion operators, and reject attempts 

Those of you that have been paying attention will have noticed that if we 
introduce a second function, eg.

subroutine test(wibble)
  USE M
  type (T0) :: wibble
end subroutine

We can legally have both
  call test(BAR)
and
  call test(BAZ)

ie. bar and wibble are considered to have the same type, as are wibble and 
baz. However bar and baz do not have the same type. In practice I think this 
means the types are different for language enforcement purposes, but the same 
for code generation purposes.

Paul



More information about the Gcc-patches mailing list