[Bug fortran/38913] Fortran does not set TYPE_CANONICAL properly
rguenth at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Thu Jun 4 10:55:00 GMT 2009
------- Comment #8 from rguenth at gcc dot gnu dot org 2009-06-04 10:55 -------
The whole-file patches now expose this problem.
! { dg-do run }
! Test the fix for PR34438, in which default initializers
! forced the derived type to be static; ie. initialized once
! during the lifetime of the programme. Instead, they should
! be initialized each time they come into scope.
!
module demo
type myint
integer :: bar = 42
end type myint
end module demo
! ...who came up with this one too.
subroutine func (retval2)
use demo
type(myint) :: foo2 = myint (77)
type(myint) :: retval2
retval2 = foo2
foo2%bar = 999
end subroutine func
subroutine other
use demo
interface
subroutine func(rv2)
use demo
type(myint) :: rv2
end subroutine func
end interface
type(myint) :: val2
call func (val2)
if ((val2%bar .ne. 77_4)) call abort ()
end subroutine other
! Run both tests.
call other
end
! { dg-final { cleanup-modules "demo M1" } }
with -O2 -fwhole-file we inline func into other and get
other ()
{
static struct myint foo2D.1539 = {.barD.1534=77};
static struct myint foo2D.1539 = {.barD.1534=77};
struct myint & retval2D.1572;
struct myint val2D.1544;
integer(kind=4)D.8 D.1547;
<bb 2>:
val2D.1544.barD.1542 = 42;
retval2D.1572_6 = (struct myint &) &val2D.1544;
*retval2D.1572_6 = foo2D.1539;
foo2D.1539.barD.1534 = 999;
D.1547_1 = val2D.1544.barD.1542;
if (D.1547_1 != 77)
which looks good sofar. But the store *retval2D.1572_6 = foo2D.1539 is
through a different struct myint than the load from val2D.1544.barD.1542
so we optimize the load to 42 -- the only visible aliasing store.
<var_decl 0x7ffff7fcbc80 val2
type <record_type 0x7ffff7fd1180 myint SI
size <integer_cst 0x7ffff7ed4a50 constant 32>
unit size <integer_cst 0x7ffff7ed46c0 constant 4>
align 32 symtab 0 alias set 2 canonical type 0x7ffff7fd1180
fields <field_decl 0x7ffff7fcbbe0 bar type <integer_type 0x7ffff7ee1540
integer(kind=4)>
SI file t.f90 line 23 col 0 size <integer_cst 0x7ffff7ed4a50 32>
unit size <integer_cst 0x7ffff7ed46c0 4>
align 32 offset_align 128
offset <integer_cst 0x7ffff7ed46f0 constant 0>
bit offset <integer_cst 0x7ffff7ed4f30 constant 0> context
<record_type 0x7ffff7fd1180 myint>>
pointer_to_this <pointer_type 0x7ffff7fd1300> chain <type_decl
0x7ffff7fd1240 D.1543>>
addressable used SI file t.f90 line 30 col 0 size <integer_cst
0x7ffff7ed4a50 32> unit size <integer_cst 0x7ffff7ed46c0 4>
align 32 context <function_decl 0x7ffff5f3f200 other>>
and
<indirect_ref 0x7ffff7ff9dc0
type <record_type 0x7ffff7fced80 myint SI
size <integer_cst 0x7ffff7ed4a50 constant 32>
unit size <integer_cst 0x7ffff7ed46c0 constant 4>
align 32 symtab 0 alias set 4 canonical type 0x7ffff7fced80
fields <field_decl 0x7ffff7fcbaa0 bar type <integer_type 0x7ffff7ee1540
integer(kind=4)>
SI file t.f90 line 15 col 0 size <integer_cst 0x7ffff7ed4a50 32>
unit size <integer_cst 0x7ffff7ed46c0 4>
align 32 offset_align 128
offset <integer_cst 0x7ffff7ed46f0 constant 0>
bit offset <integer_cst 0x7ffff7ed4f30 constant 0> context
<record_type 0x7ffff7fced80 myint>>
reference_to_this <reference_type 0x7ffff7fcef00> chain <type_decl
0x7ffff7fcee40 D.1535>>
arg 0 <ssa_name 0x7ffff5f4a060
type <reference_type 0x7ffff7fcef00 type <record_type 0x7ffff7fced80
myint>
public unsigned DI
size <integer_cst 0x7ffff7ed4b40 constant 64>
unit size <integer_cst 0x7ffff7ed4b70 constant 8>
align 64 symtab 0 alias set -1 canonical type 0x7ffff7fcef00>
visited var <var_decl 0x7ffff5f46780 retval2>def_stmt retval2_6 =
(struct myint &) &val2;
version 6
ptr-info 0x7ffff7f9ac10>>
so the Frontend misses proper type unification.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38913
More information about the Gcc-bugs
mailing list