Bug 41772 - [4.4 Regression] Wrong code due to TRANSFER of EMPTY array section
Summary: [4.4 Regression] Wrong code due to TRANSFER of EMPTY array section
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P4 normal
Target Milestone: 4.4.3
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on:
Blocks: 32834 41777
  Show dependency treegraph
 
Reported: 2009-10-20 19:52 UTC by Tobias Burnus
Modified: 2009-11-02 17:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.3 4.2.1 4.3.4
Known to fail: 4.4.1 4.5.0
Last reconfirmed: 2009-10-21 15:37:12


Attachments
input.xml (515 bytes, text/plain)
2009-10-20 19:52 UTC, Tobias Burnus
Details
Fix for the PR (256 bytes, patch)
2009-10-22 09:55 UTC, Paul Thomas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-10-20 19:52:09 UTC
Non-reduced testcase:

wget http://www.uszla.me.uk/FoX/source/FoX-4.0.4.tar.gz
tar xfz FoX-4.0.4.tar.gz
cd FoX-4.0.4 && ./configure FC=gfortran && make -j4

cat <<EOF > fox.f90
use FoX_dom
implicit none
type(Node), pointer :: doc
type(DOMConfiguration),pointer :: config
config => newDOMConfig()
call setParameter(config, "validate-if-schema", .true.)
doc => parseFile("input.xml",config)
end
EOF

gfortran -Iobjs/finclude fox.f90 objs/lib/libFoX_{dom,utils,sax,common,fsys}.a
./a.out
Segmentation fault (core dumped)

Needs the attached "input.xml". Testcase works with NAG f95.
Comment 1 Tobias Burnus 2009-10-20 19:52:50 UTC
Created attachment 18846 [details]
input.xml
Comment 2 Tobias Burnus 2009-10-20 20:31:37 UTC
For input.xml "<point coord="0" />" is enough.

Valgrind shows the following (and some more str_vs / vs_str / str_alloc invalid reads). str_vs and vs_str convert (TRANSFER) a multi-character string into  a char(1) array and vice versa.


 Invalid read of size 1
    at 0x4C256E8: memcpy (mc_replace_strmem.c:482)
    by 0x4C0160: __fox_m_fsys_array_str_MOD_str_vs (fox_m_fsys_array_str.F90:46)
    by 0x49B050: __m_common_namespaces_MOD_checknamespaces (m_common_namespaces.F90:603)
    by 0x46B726: open_tag.1918 (m_sax_parser.F90:2360)
    by 0x4549E9: __m_sax_parser_MOD_sax_parse (m_sax_parser.F90:843)
    by 0x401987: __m_dom_parse_MOD_runparser (m_dom_parse.f90:500)
    by 0x4016E9: __m_dom_parse_MOD_parsefile (m_dom_parse.f90:547)
    by 0x40143B: MAIN__ (fox.f90:7)
    by 0x40147A: main (fox.f90:1)
Comment 3 Tobias Burnus 2009-10-20 21:16:58 UTC
Reduced testcase. The problem is - as often - the empty array section.
With 4.1, 4.2 and 4.3 it works, while with 4.4 and 4.5 I get a segfault.

module m
implicit none
contains
  pure function str_vs(vs) result(s)
    character, dimension(:), intent(in) :: vs
    character(len=size(vs)) :: s
    s = transfer(vs, s)
  end function str_vs
  subroutine has_key_ns(uri, localname)
    character(len=*), intent(in) :: uri, localname
  end subroutine
end module m

use m
implicit none
character, dimension(:), pointer :: QName
integer :: n
allocate(qname(6))
qname = (/ 'a','b','c','d','e','f' /)
n = 0
call has_key_ns(str_vs(qname(1:n-1)),"")
deallocate(qname)
end
Comment 4 Tobias Burnus 2009-10-20 21:45:41 UTC
Working: 2009-01-16-r143426
Failing: 2009-01-17-r143463


Possibly caused by:

r143462 | pault | 2009-01-17 12:32:02 +0100 (Sat, 17 Jan 2009) | 17 lines
http://gcc.gnu.org/viewcvs?view=rev&revision=143462

2009-01-17  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/34955
        * trans-intrinsic.c (gfc_conv_intrinsic_array_transfer): Has
        been absorbed into gfc_conv_intrinsic_transfer. All
        references to it in trans-intrinsic.c have been changed
        accordingly.  PR fixed by using a temporary for scalar
        character transfer, when the source is shorter than the
        destination.

2009-01-17  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/34955
        * gfortran.dg/transfer_intrinsic_1.f90: New test.
        * gfortran.dg/transfer_intrinsic_2.f90: New test.
Comment 5 Paul Thomas 2009-10-22 09:55:52 UTC
Created attachment 18864 [details]
Fix for the PR

This is, as yet, not regtested etc.  I'll do so on Saturday, when back from my travels, and commit as 'obvious' (with ChangeLogs and testcase).

Cheers

Paul
Comment 6 Paul Thomas 2009-10-24 10:11:59 UTC
Subject: Bug 41772

Author: pault
Date: Sat Oct 24 10:11:46 2009
New Revision: 153524

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153524
Log:
2009-10-24  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41772
	* trans-intrinsic.c (gfc_conv_intrinsic_transfer): Stop'extent'
	from going negative.

2009-10-24  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41772
	* gfortran.dg/transfer_intrinsic_3.f90.


Added:
    trunk/gcc/testsuite/gfortran.dg/transfer_intrinsic_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Tobias Burnus 2009-11-02 16:31:09 UTC
Subject: Bug 41772

Author: burnus
Date: Mon Nov  2 16:30:48 2009
New Revision: 153817

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153817
Log:
2009-11-02  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/41772
        * trans-intrinsic.c (gfc_conv_intrinsic_transfer): Stop'extent'
        from going negative.

2009-11-02  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/41772
        * gfortran.dg/transfer_intrinsic_3.f90.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/transfer_intrinsic_3.f90
Modified:
    branches/gcc-4_4-branch/gcc/fortran/ChangeLog
    branches/gcc-4_4-branch/gcc/fortran/trans-intrinsic.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 8 Tobias Burnus 2009-11-02 17:08:11 UTC
... and backported to 4.4. Thanks Paul for the patch.

Closed as FIXED.