Bug 40847 - [4.3 Regression] segfault & bogus warning
[4.3 Regression] segfault & bogus warning
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.5.0
: P4 normal
: 4.3.5
Assigned To: Paul Thomas
: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2009-07-24 17:36 UTC by Joost VandeVondele
Modified: 2009-08-16 21:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2 4.5.0
Known to fail: 4.4.1 4.3.3
Last reconfirmed: 2009-07-25 16:59:55


Attachments
A provisional patch for the PR (1.78 KB, patch)
2009-08-05 14:47 UTC, Paul Thomas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2009-07-24 17:36:50 UTC
this should be an OK program, but gives a strange warning, and segfaults at run time. 4.1.2 works fine.

program test_elemental

print *,'Transfer size:',transfer_size((/0.,0./),(/'a','b'/))

contains

   elemental function transfer_size (source, mold)
     real, intent(in)         :: source
     character(*), intent(in) :: mold
     integer                  :: transfer_size
     transfer_size = SIZE(TRANSFER(source, (/mold/)))
     return
   end function transfer_size

end program test_elemental
Comment 1 Francois-Xavier Coudert 2009-07-25 16:59:55 UTC
Reduced testcase:

  subroutine transfer_size (source, mold)
    real :: source 
    character(*) :: mold
    print *, ichar(transfer(source, (/mold/)))
  end subroutine

(can then be tested at runtime with "call transfer_size(exp(1.),'a')").
Comment 2 Tobias Burnus 2009-07-27 10:08:39 UTC
The following looks wrong:

gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
                      gfc_expr *mold, gfc_expr *size)
[...]
  if (mold->ts.type == BT_CHARACTER && !mold->ts.cl->length
        && !(mold->expr_type == EXPR_VARIABLE
             && mold->symtree->n.sym->attr.dummy))
    mold->ts.cl->length = gfc_int_expr (mold->value.character.length);

For the testcase:
  mold->ts.type == BT_CHARACTER
  mold->ts.cl->length == NULL
  mold->expr_type == EXPR_VARIABLE
  mold->symtree == NULL  (!)
and
  mold->value.character.length == 19532032
Comment 3 Tobias Burnus 2009-07-27 12:57:20 UTC
The real issue is that mold->expr_type is EXPR_VARIABLE and not EXPR_ARRAY. In gfc_simplify_transfer everything is fine: mold->expr_type is EXPR_ARRAY but in gfc_resolve_transfer it is already wrong. Must go wrong somewhere during resolution ...
Comment 4 Richard Biener 2009-08-04 12:30:18 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 5 Paul Thomas 2009-08-05 14:47:33 UTC
Created attachment 18305 [details]
A provisional patch for the PR

(In reply to comment #3)
> The real issue is that mold->expr_type is EXPR_VARIABLE and not EXPR_ARRAY. In
> gfc_simplify_transfer everything is fine: mold->expr_type is EXPR_ARRAY but in
> gfc_resolve_transfer it is already wrong. Must go wrong somewhere during
> resolution ...
> 

No, this is not the problem.  The fault is that the mold character length is being incorrectly set in gfc_resolve_transfer.

The patch is regtesting.  If there are any FAILS it will be a matter of correcting the condition.

Cheers

Paul
Comment 6 Paul Thomas 2009-08-05 16:10:36 UTC
Subject: Bug 40847

Author: pault
Date: Wed Aug  5 16:10:19 2009
New Revision: 150493

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

	PR fortran/40847
	* iresolve.c (gfc_resolve_transfer): Correct error in 'mold'
	character length for case where length expresson is NULL.

2009-08-05  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40847
	* gfortran.dg/transfer_resolve_1.f90 : New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/transfer_resolve_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Paul Thomas 2009-08-16 20:04:59 UTC
Subject: Bug 40847

Author: pault
Date: Sun Aug 16 20:04:40 2009
New Revision: 150810

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

	PR fortran/40847
	* iresolve.c (gfc_resolve_transfer): Correct error in 'mold'
	character length for case where length expresson is NULL.

2009-08-16  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40847
	* gfortran.dg/transfer_resolve_1.f90 : New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/transfer_resolve_1.f90
Modified:
    branches/gcc-4_4-branch/gcc/fortran/ChangeLog
    branches/gcc-4_4-branch/gcc/fortran/iresolve.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog

Comment 8 Paul Thomas 2009-08-16 21:02:04 UTC
Subject: Bug 40847

Author: pault
Date: Sun Aug 16 21:01:50 2009
New Revision: 150815

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

	PR fortran/40847
	* iresolve.c (gfc_resolve_transfer): Correct error in 'mold'
	character length for case where length expresson is NULL.

2009-08-16  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/40847
	* gfortran.dg/transfer_resolve_1.f90 : New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/transfer_resolve_1.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/iresolve.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 9 Paul Thomas 2009-08-16 21:02:37 UTC
Fixed on trunk, 4.4 and 4.3.

Paul
Comment 10 Paul Thomas 2009-08-16 21:03:13 UTC
I missed 'fixed' !