public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/65504] New: [4.9/5 Regression] select case with strings and -fgcse -O
@ 2015-03-21 13:19 tkoenig at gcc dot gnu.org
  2015-03-21 13:54 ` [Bug middle-end/65504] " tkoenig at gcc dot gnu.org
                   ` (24 more replies)
  0 siblings, 25 replies; 26+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2015-03-21 13:19 UTC (permalink / raw)
  To: gcc-bugs

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)


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-06-03 21:43 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-21 13:19 [Bug middle-end/65504] New: [4.9/5 Regression] select case with strings and -fgcse -O tkoenig at gcc dot gnu.org
2015-03-21 13:54 ` [Bug middle-end/65504] " tkoenig at gcc dot gnu.org
2015-03-21 14:10 ` [Bug rtl-optimization/65504] " tkoenig at gcc dot gnu.org
2015-03-21 14:40 ` dominiq at lps dot ens.fr
2015-03-21 14:56 ` tkoenig at gcc dot gnu.org
2015-03-21 15:12 ` tkoenig at gcc dot gnu.org
2015-03-21 15:15 ` howarth at bromo dot med.uc.edu
2015-03-21 15:24 ` howarth at bromo dot med.uc.edu
2015-03-21 15:45 ` dominiq at lps dot ens.fr
2015-03-21 15:59 ` tkoenig at gcc dot gnu.org
2015-03-21 18:30 ` howarth at bromo dot med.uc.edu
2015-03-21 18:38 ` howarth at bromo dot med.uc.edu
2015-03-21 18:42 ` howarth at bromo dot med.uc.edu
2015-03-21 20:14 ` sebastian.beyer at riseup dot net
2015-03-21 20:41 ` hjl.tools at gmail dot com
2015-03-21 22:23 ` ebotcazou at gcc dot gnu.org
2015-03-22 18:52 ` ebotcazou at gcc dot gnu.org
2015-03-23  9:57 ` rguenth at gcc dot gnu.org
2015-03-23 13:02 ` jakub at gcc dot gnu.org
2015-03-23 13:02 ` [Bug target/65504] " jakub at gcc dot gnu.org
2015-03-23 13:51 ` ebotcazou at gcc dot gnu.org
2015-03-23 14:18 ` jakub at gcc dot gnu.org
2015-03-23 15:45 ` jakub at gcc dot gnu.org
2015-03-23 15:49 ` [Bug target/65504] [4.9 " jakub at gcc dot gnu.org
2015-06-03 15:31 ` jakub at gcc dot gnu.org
2015-06-03 21:43 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).