Bug 34537 - ICE or wrong code for TRANSFER of constant string to character
Summary: ICE or wrong code for TRANSFER of constant string to character
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid, wrong-code
Depends on:
Blocks: 31237 32834
  Show dependency treegraph
 
Reported: 2007-12-20 08:41 UTC by Tobias Burnus
Modified: 2008-01-11 18:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-12-20 18:23:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-12-20 08:41:01 UTC
Found at http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/5a1e0cc2c7eb95cc/

   character, pointer :: ptr(:)
   allocate(ptr(8))
   ptr = transfer('Sample'//achar(0),ptr) ! Causes ICE
end

gives a Floating Point Exception.
Comment 1 Tobias Burnus 2007-12-20 08:42:15 UTC
gdb shows:

Program received signal SIGFPE, Arithmetic exception.

0x000000000046b86e in gfc_simplify_transfer (source=0x26a7b30, mold=0x1, size=0x0)
    at /projects/tob/gcc/gcc/fortran/simplify.c:4138
4138              result_length = source_size / result_elt_size;

#0  0x000000000046b86e in gfc_simplify_transfer (source=0x26a7b30, mold=0x1, size=0x0)
    at /projects/tob/gcc/gcc/fortran/simplify.c:4138
#1  0x000000000042aec3 in do_simplify (specific=0x2687a10, e=0x26a7a60) at /projects/tob/gcc/gcc/fortran/intrinsic.c:3187
#2  0x000000000042bd3a in gfc_intrinsic_func_interface (expr=0x26a7a60, error_flag=1)
    at /projects/tob/gcc/gcc/fortran/intrinsic.c:3446
Comment 2 Tobias Burnus 2007-12-20 10:57:07 UTC
    at /projects/tob/gcc/gcc/fortran/simplify.c:4138
4138              result_length = source_size / result_elt_size;

Here, source_size is correctly 8, but result_elt_size == 0 instead of 1 (character(len=1)).

The following fails at run time (nothing is printed):

program main
  implicit none
  character(len=8) :: t
  call test(t)
  print *, t
contains
  subroutine test(a)
    character(len=*) :: a
    a = transfer('Sample',a)
  end subroutine test
end program main


The following ill-defined program gives another ICE:
   compiler error: in gfc_interpret_character, at fortran/target-memory.c:360
(It is ill defined because the source size is smaller than the result size; cf. PR 33037. NAG f95 prints "Intrinsic TRANSFER has partly undefined result")

program main
  implicit none
  character(len=8), target :: t
  character(len=8), pointer :: p
  p => t
  call test(p)
  print *, t
contains
  subroutine test(a)
    character(len=8),pointer :: a
    a = transfer('Sample',a)
  end subroutine test
end program main
Comment 3 Tobias Burnus 2008-01-11 14:21:31 UTC
Paul's patch (approved): http://gcc.gnu.org/ml/fortran/2008-01/msg00131.html
Comment 4 Paul Thomas 2008-01-11 18:26:16 UTC
Subject: Bug 34537

Author: pault
Date: Fri Jan 11 18:25:29 2008
New Revision: 131470

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

	PR fortran/34537
	* simplify.c (gfc_simplify_transfer): Return NULL if the size
	of the element is unavailable and only assign character length
	to the result, if 'mold' is constant.

2008-01-11  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34537
	* gfortran.dg/transfer_simplify_8.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/transfer_simplify_8.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Paul Thomas 2008-01-11 18:27:01 UTC
Fixed on trunk

Paul