The following produces a segfault at runtime with -O2 and higher module m type t real x contains procedure, pass :: a end type contains real function a (arg) class (t) :: arg a = arg%x end function real function b (arg) real :: arg b = arg*2 end function subroutine s class(t), allocatable :: z allocate(z) ! see tree-optimized output z%x = 42 ! see tree-optimized output print *, b (z%a()) ! see tree-optimized output end subroutine end module use m call s end With -O0, the marked lines give <bb 2>: D.1348_1 = malloc (4); if (D.1348_1 == 0B) goto <bb 3>; else goto <bb 4>; <bb 3>: _gfortran_os_error (&"Out of memory"[1]{lb: 1 sz: 1}); <bb 4>: D.1374_2 = (struct t *) D.1348_1; z.$data = D.1374_2; z.$vindex = 2800126; z.$size = 4; D.1375_3 = z.$data; D.1375_3->x = 4.2e+1; dt_parm.0.common.filename = &"test.f03"[1]{lb: 1 sz: 1}; dt_parm.0.common.line = 22; dt_parm.0.common.flags = 128; dt_parm.0.common.unit = 6; _gfortran_st_write (&dt_parm.0); D.1376_4 = __m_MOD_a (&z); D.1350 = D.1376_4; D.1377_5 = __m_MOD_b (&D.1350); D.1351 = D.1377_5; _gfortran_transfer_real (&dt_parm.0, &D.1351, 4); _gfortran_st_write_done (&dt_parm.0); whilst with -O2 <bb 2>: D.1348_1 = malloc (4); if (D.1348_1 == 0B) goto <bb 3>; else goto <bb 4>; <bb 3>: _gfortran_os_error (&"Out of memory"[1]{lb: 1 sz: 1}); <bb 4>: D.1374_2 = (struct t *) D.1348_1; dt_parm.0.common.filename = &"test.f03"[1]{lb: 1 sz: 1}; dt_parm.0.common.line = 22; dt_parm.0.common.flags = 128; dt_parm.0.common.unit = 6; _gfortran_st_write (&dt_parm.0); arg_21 = (struct .class.t & restrict) &z; D.1389_22 = arg_21->$data; D.1386_23 = D.1389_22->x; D.1392_26 = D.1386_23 * 2.0e+0; D.1351 = D.1392_26; _gfortran_transfer_real (&dt_parm.0, &D.1351, 4); _gfortran_st_write_done (&dt_parm.0); ie. the important part of the allocation and the entire assignment disappear! Since the PRINT then tries to access the data component of the CLASS object, the segfault results
Confirmed on (i686|powerpc)-apple-darwin9 revision 152966. On
Have cc'd Richi to see if he can shed any light on this. Paul
At r160335, I don't see the failure on x86_64-unknown-linux-gnu. Maybe it has been fixed by some middle-end changes by now. Can anyone confirm that the error is gone?
> At r160335, I don't see the failure on x86_64-unknown-linux-gnu. Maybe it has > been fixed by some middle-end changes by now. Can anyone confirm that the error > is gone? No error for the flags I have tried on x86_64-apple-darwin10.3.0 and powerpc-apple-darwin9.
(In reply to comment #4) It's fixed for me too. x86_64/FC9 I'll mark it as fixed - thanks for noting that it had gone. Paul