[Bug middle-end/65504] New: [4.9/5 Regression] select case with strings and -fgcse -O
tkoenig at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Mar 21 13:19:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65504
Bug ID: 65504
Summary: [4.9/5 Regression] select case with strings and -fgcse
-O
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: tkoenig at gcc dot gnu.org
Original bug report from
https://stackoverflow.com/questions/29163373/why-do-i-have-random-return-values-in-my-type-in-fortran-with-o2
by "Sebastian".
The following program
program testbug
implicit none
integer, parameter :: STRLEN = 256
type :: ncVarnames_t
! variables names for the different ice models
character (len=STRLEN) :: surf
character (len=STRLEN) :: x, y
character (len=STRLEN) :: bed
character (len=STRLEN) :: thick
end type ncVarnames_t
type (ncVarnames_t) :: testvar
type (ncVarnames_t) :: testvar2
print *, "hello"
testvar = get_ncVarnames ("test")
testvar2 = get_ncVarnames ("test")
print *, trim(testvar%surf)
print *, trim(testvar%bed)
print *, trim(testvar%bed)
print *, trim(testvar%surf)
contains
type (ncVarnames_t) function get_ncVarnames (model) result (v)
character(len=*), intent(in) :: model
! type (ncVarnames_t) :: v
select case (model)
case ("test")
! test model
v%x = 'x'
v%y = 'y'
v%surf = 'surf'
v%bed = 'bed'
case ("pism")
! pism data
v%x = 'x'
v%y = 'y'
v%surf = 'usurf'
v%bed = 'topg'
case default
print *, "unknown model, please use one of [test pism sico]"
stop
end select
end function get_ncVarnames
end program testbug
prints random values with 4.9 and 5.0 when invoked with -O -fgcse or with -O2,
but not with 4.8 or when -fgcse is missing. Valgrind complains with
==4327== Syscall param write(buf) points to uninitialised byte(s)
==4327== at 0x522FE80: __write_nocancel (in /lib64/libc-2.18.so)
==4327== by 0x4F1B6B7: raw_write (unix.c:323)
==4327== by 0x4F2234E: _gfortrani_fbuf_flush (unix.h:59)
==4327== by 0x4F17437: _gfortrani_next_record (transfer.c:3528)
==4327== by 0x4F19E32: finalize_transfer (transfer.c:3616)
==4327== by 0x4F19FB8: _gfortran_st_write_done (transfer.c:3741)
==4327== by 0x400C02: MAIN__ (in /home/ig25/Krempel/Select/a.out)
==4327== by 0x400D09: main (in /home/ig25/Krempel/Select/a.out)
==4327== Address 0x5c5fbe1 is 1 bytes inside a block of size 512 alloc'd
==4327== at 0x4C277AB: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==4327== by 0x4E4F964: _gfortrani_xmalloc (memory.c:43)
==4327== by 0x4F221EC: _gfortrani_fbuf_init (fbuf.c:43)
==4327== by 0x4F1ACFE: _gfortrani_init_units (unit.c:650)
==4327== by 0x4E4EF67: init (main.c:265)
==4327== by 0x400E859: call_init.part.0 (in /lib64/ld-2.18.so)
==4327== by 0x400E942: _dl_init (in /lib64/ld-2.18.so)
==4327== by 0x40011C9: ??? (in /lib64/ld-2.18.so)
More information about the Gcc-bugs
mailing list