https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66907
kargl at gcc dot gnu.org changed:
What|Removed |Added
CC||kargl at gcc dot gnu.org
--- Comment #1 from kargl at gcc dot gnu.org ---
(In reply to mrestelli from comment #0)
The attached code compiles with gfortran and produces an error at
runtime. As far as I can see, the code is correct. Unfortunately, I
have been unable to reduce the test further; if I try, the problem
disappears.
$ gfortran gft.f90 -g -O0 -o gft
$ ./gft
Program received signal SIGSEGV: Segmentation fault - invalid memory
reference.
Backtrace for this error:
#0 0x7F281A1F6757
#1 0x7F281A1F6D5E
#2 0x7F281972EE8F
#3 0x400A15 in __mod_a_MOD_mult at gft.f90:67
#4 0x400F44 in __mod_a_MOD_check_t_b at gft.f90:38 (discriminator 2)
#5 0x401160 in test at gft.f90:84 (discriminator 2)
Speicherzugriffsfehler
$ gfortran --version
GNU Fortran (GCC) 6.0.0 20150715 (experimental)
Copyright (C) 2015 Free Software Foundation, Inc.
The correct behaviour should be
$ ./gft
p(1):1
p(2):1
Program appears to function correctly if one uses -O or -O2.
% gfc6 -o z -O er.f90
% ./z
p(1):1
p(2):1
without optimization one gets
(gdb) run
Starting program: /mnt/sgk/tmp/z
Program received signal SIGSEGV, Segmentation fault.
0x00400cb5 in mod_a::mult (p1=..., p2=...) at er.f90:57
57p1_dat = p1%dat(1)
It also works without optimization if one uses a temp variable
in check_t_b().
pure recursive function check_t_b(d) result(b)
integer, intent(in) :: d
type(t_b) :: b(2)
type(t_b) :: xd, tmp
xd = 1.0
if(d.eq.1) then
b = 1.0
else
tmp = xd**0
b = tmp*check_t_b(1)
endif