public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/33037]  New: TRANSFER intrinsic is context sensitive
@ 2007-08-09 14:33 drewmccormack at mac dot com
  2007-08-09 15:51 ` [Bug fortran/33037] " burnus at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: drewmccormack at mac dot com @ 2007-08-09 14:33 UTC (permalink / raw)
  To: gcc-bugs

When using the transfer intrinsic to convert a character string to an array of
integers, and the string does not fit exactly into the integer array data
block, the resultant integer array is scope dependent, with the same code
giving a different resultant integer array in different subroutines/program
units. Basically, the transfer function is not deterministic in the case where
the source data is smaller than the destination data.

There is a small program below to demonstrate the issue. The integer array is
printed twice, and (on my machine) is different each time. The code producing
the two sets of output is exactly the same, but in the first case the code is
embedded in the main program, and in the other case in a subroutine.

I do not have a copy of the standard, but I cannot imagine that this behavior
is correct. The problem arises even if the destination array is initialized to
zero (as shown in the example).


module DataMod
   type Byte
      character(len=1) :: singleByte
   end type
end module

subroutine sub()
   use DataMod
   integer :: i(1), intarray(4), j
   character(len=15) :: str1
   type (Byte) :: bytes(15)
   type (Byte) :: byteProt(1)

   bytes = transfer('123456789012345', byteProt)
   print *, bytes(:)%singleByte
   intarray = 0
   intarray = transfer(bytes, i)
   print *, intarray

end subroutine

program test
   use DataMod
   integer :: i(1), intarray(4), j
   character(len=15) :: str1
   type (Byte) :: bytes(15)
   type (Byte) :: byteProt(1)

   bytes = transfer('123456789012345', byteProt)
   print *, bytes(:)%singleByte
   intarray = 0
   intarray = transfer(bytes, i)
   print *, intarray

   call sub()

end program


-- 
           Summary: TRANSFER intrinsic is context sensitive
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: drewmccormack at mac dot com
 GCC build triplet: gcc version 4.3.0 20070511 (experimental)
  GCC host triplet: powerpc-apple-darwin8.9.0
GCC target triplet: powerpc-apple-darwin8.9.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER intrinsic is context sensitive
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
@ 2007-08-09 15:51 ` burnus at gcc dot gnu dot org
  2007-08-09 15:59 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-08-09 15:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2007-08-09 15:50 -------
Could you please tell us your gfortran version? ("gfortran -v", the gcc-version
line is of most interest.)

Not that TRANSFER is free of bugs, but it produces here 4.3.0 20070808
(x86_64-unknown-linux-gnu) the same result as NAG f95. NAG f95 warns:
Warning: a.f90, line 17: Intrinsic TRANSFER has partly undefined result
Warning: a.f90, line 32: Intrinsic TRANSFER has partly undefined result

If one runs valgrind on the a.out as produced by gfortran (-m64; no errors
shown for -m32):
==21023== Conditional jump or move depends on uninitialised value(s)
==21023==    at 0x4E3DD77: _gfortrani_gfc_itoa (error.c:138)
==21023==    by 0x4EC0AA3: write_integer (write.c:1343)
==21023==    by 0x4EC2BCA: _gfortrani_list_formatted_write (write.c:1541)
==21023==    by 0x4EBA76A: _gfortran_transfer_array (transfer.c:1513)
==21023==    by 0x40138E: MAIN__ (in /dev/shm/a.out)
==21023==    by 0x4013DB: main (fmain.c:22)
(and some more of these kind). [Actually, g95 has a similar valgrind output;
for NAG f95, ifort and openf95 valgrind finds no error.]

This PR could be related to PR 31610.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER intrinsic is context sensitive
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
  2007-08-09 15:51 ` [Bug fortran/33037] " burnus at gcc dot gnu dot org
@ 2007-08-09 15:59 ` pinskia at gcc dot gnu dot org
  2007-08-09 18:54 ` burnus at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-09 15:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-08-09 15:59 -------
This is undefined code, when I rewrote most of the transfer code for scalars, I
had asked what happens when the sizes did not match and everyone I asked said
it was undefined behavior.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER intrinsic is context sensitive
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
  2007-08-09 15:51 ` [Bug fortran/33037] " burnus at gcc dot gnu dot org
  2007-08-09 15:59 ` pinskia at gcc dot gnu dot org
@ 2007-08-09 18:54 ` burnus at gcc dot gnu dot org
  2007-08-09 22:58 ` [Bug fortran/33037] TRANSFER should warn on mismatched sizes fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-08-09 18:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2007-08-09 18:54 -------
> This is undefined code, when I rewrote most of the transfer code for scalars, I
> had asked what happens when the sizes did not match and everyone I asked said
> it was undefined behavior.

Well, nonetheless gfortran could be that kind to follow NAG f95 and print
"Intrinsic TRANSFER has partly undefined result".


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
                   ` (2 preceding siblings ...)
  2007-08-09 18:54 ` burnus at gcc dot gnu dot org
@ 2007-08-09 22:58 ` fxcoudert at gcc dot gnu dot org
  2007-08-10  8:47 ` pault at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-09 22:58 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2007-08-09 22:58:12
               date|                            |
            Summary|TRANSFER intrinsic is       |TRANSFER should warn on
                   |context sensitive           |mismatched sizes


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
                   ` (3 preceding siblings ...)
  2007-08-09 22:58 ` [Bug fortran/33037] TRANSFER should warn on mismatched sizes fxcoudert at gcc dot gnu dot org
@ 2007-08-10  8:47 ` pault at gcc dot gnu dot org
  2007-09-17 16:29 ` burnus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-08-10  8:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pault at gcc dot gnu dot org  2007-08-10 08:47 -------
Just for the record:

13.14.110 TRANSFER (SOURCE, MOLD [, SIZE])
...snip...
Result Value. If the physical representation of the result has the same length
as that of SOURCE, the physical representation of the result is that of SOURCE.

***If the physical representation of the result is longer than that of SOURCE,
the physical representation of the leading part is that of SOURCE and the
remainder is undefined.***

If the physical representation of the result is shorter than that of SOURCE,
the physical representation of the result is the leading part of SOURCE. If D
and E are scalar variables such that the physical representation of D is as
long as or longer than that of E, the value of TRANSFER (TRANSFER (E, D), E)
shall be the value of E. IF D is an array and E is an array of rank one, the
value of TRANSFER (TRANSFER (E, D), E, SIZE (E)) shall be the value of E.

Paul


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
                   ` (4 preceding siblings ...)
  2007-08-10  8:47 ` pault at gcc dot gnu dot org
@ 2007-09-17 16:29 ` burnus at gcc dot gnu dot org
  2007-09-21 10:22 ` burnus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-09-17 16:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from burnus at gcc dot gnu dot org  2007-09-17 16:29 -------
Simple patch; catches if result size > source size (cf. example in bug 31610
comment 0). However, it does not catch if result size < LHS variable. (Example
in this PR.)

Index: simplify.c
===================================================================
--- simplify.c  (Revision 128550)
+++ simplify.c  (Arbeitskopie)
@@ -4059,6 +4059,11 @@
       result_size = result_elt_size;
     }

+  if (source_size < result_size)
+    gfc_warning("Intrinsic TRANSFER at %L has partly undefined result: source
"
+               "size %ld < result size %ld", &source->where,
+               (long) source_size, (long) result_size);
+
   /* Allocate the buffer to store the binary version of the source.  */
   buffer_size = MAX (source_size, result_size);
   buffer = (unsigned char*)alloca (buffer_size);


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
                   ` (5 preceding siblings ...)
  2007-09-17 16:29 ` burnus at gcc dot gnu dot org
@ 2007-09-21 10:22 ` burnus at gcc dot gnu dot org
  2007-09-21 10:32 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-09-21 10:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2007-09-21 10:21 -------
Subject: Bug 33037

Author: burnus
Date: Fri Sep 21 10:21:29 2007
New Revision: 128646

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128646
Log:
2007-09-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/33037
        * simplify.c (gfc_simplify_transfer): Warn if source size
        is smaller than result size.

2007-09-21  Tobias Burnus  <burnus@net-b.de>

        PR fortran/33037
        * gfortran.dg/transfer_check_1.f90: New.


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


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
                   ` (6 preceding siblings ...)
  2007-09-21 10:22 ` burnus at gcc dot gnu dot org
@ 2007-09-21 10:32 ` burnus at gcc dot gnu dot org
  2007-09-22  1:37 ` patchapp at dberlin dot org
  2008-01-11 14:13 ` burnus at gcc dot gnu dot org
  9 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-09-21 10:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from burnus at gcc dot gnu dot org  2007-09-21 10:32 -------
Partially fixed.

Missing: Check whether the size of the LHS is bigger than the result of
TRANSFER (see example in this PR's comment 0).

The current fix gives the warning only if the specified (SIZE=...) result size
is larger than the source size (cf. example in bug 31610 comment 0).


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  GCC build triplet|gcc version 4.3.0 20070511  |
                   |(experimental)              |
   GCC host triplet|powerpc-apple-darwin8.9.0   |
 GCC target triplet|powerpc-apple-darwin8.9.0   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
                   ` (7 preceding siblings ...)
  2007-09-21 10:32 ` burnus at gcc dot gnu dot org
@ 2007-09-22  1:37 ` patchapp at dberlin dot org
  2008-01-11 14:13 ` burnus at gcc dot gnu dot org
  9 siblings, 0 replies; 12+ messages in thread
From: patchapp at dberlin dot org @ 2007-09-22  1:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from patchapp at dberlin dot org  2007-09-22 01:36 -------
Subject: Bug number PR33037

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2007-09/msg01664.html


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
  2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
                   ` (8 preceding siblings ...)
  2007-09-22  1:37 ` patchapp at dberlin dot org
@ 2008-01-11 14:13 ` burnus at gcc dot gnu dot org
  9 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-01-11 14:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from burnus at gcc dot gnu dot org  2008-01-11 14:02 -------
For the following ill-defined program, also a warning should be printed. It
comes from PR 34537 and had before an ICE. 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


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037


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

* [Bug fortran/33037] TRANSFER should warn on mismatched sizes
       [not found] <bug-33037-4@http.gcc.gnu.org/bugzilla/>
@ 2011-08-05 23:14 ` tkoenig at gcc dot gnu.org
  0 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-08-05 23:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33037

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |tkoenig at gcc dot gnu.org
         Resolution|                            |FIXED

--- Comment #10 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2011-08-05 23:13:58 UTC ---
The test cases now yield an error with -Wsurprising, after the fix
for PR 37211.

Closing as fixed.


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

end of thread, other threads:[~2011-08-05 23:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-09 14:33 [Bug fortran/33037] New: TRANSFER intrinsic is context sensitive drewmccormack at mac dot com
2007-08-09 15:51 ` [Bug fortran/33037] " burnus at gcc dot gnu dot org
2007-08-09 15:59 ` pinskia at gcc dot gnu dot org
2007-08-09 18:54 ` burnus at gcc dot gnu dot org
2007-08-09 22:58 ` [Bug fortran/33037] TRANSFER should warn on mismatched sizes fxcoudert at gcc dot gnu dot org
2007-08-10  8:47 ` pault at gcc dot gnu dot org
2007-09-17 16:29 ` burnus at gcc dot gnu dot org
2007-09-21 10:22 ` burnus at gcc dot gnu dot org
2007-09-21 10:32 ` burnus at gcc dot gnu dot org
2007-09-22  1:37 ` patchapp at dberlin dot org
2008-01-11 14:13 ` burnus at gcc dot gnu dot org
     [not found] <bug-33037-4@http.gcc.gnu.org/bugzilla/>
2011-08-05 23:14 ` tkoenig 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).