public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/29951]  New: incorrect conversion from string to integer by convert()
@ 2006-11-23  9:24 kloedej at knmi dot nl
  2006-11-23  9:28 ` [Bug fortran/29951] " kloedej at knmi dot nl
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: kloedej at knmi dot nl @ 2006-11-23  9:24 UTC (permalink / raw)
  To: gcc-bugs

Dear people,

The sample code below converts 4 characters to an integer using the transfer
function. If the characters are stored in an array of characters this works
fine. If the characters are stored in a string the transfer fails.

The following commands were used to compile with both gfortran and pgf90 (also
ifort and g95 give the same output as pgf90):
gfortran -o test_convert test_convert.F90
pgf90 -o test_convert test_convert.F90

When executed the program produces the following output:

pgf90 result:
 byte_string =           157          127          100            0
 byte_array  =           157          127          100            0
 byte_string: value =       6586269
 byte_array:  value =       6586269
 byte_string holds             4  bytes
 byte_array holds             4  bytes

gfortran result:
 byte_string =          157         127         100           0
 byte_array  =          157         127         100           0
 byte_string: value =          157
 byte_array:  value =      6586269
 byte_string holds            4  bytes
 byte_array holds            4  bytes

sample code:

program test_convert

  implicit none
  character(len=4)              :: byte_string
  character(len=1),dimension(4) :: byte_array
  integer*4 :: value,n,i

  byte_string(1:1) = char(157)
  byte_string(2:2) = char(127)
  byte_string(3:3) = char(100)
  byte_string(4:4) = char(0)

  byte_array(1:4) = (/char(157),char(127),char(100),char(0)/)

  print *,"byte_string = ",(ichar(byte_string(i:i)),i=1,4)
  print *,"byte_array  = ",(ichar(byte_array( i:i)),i=1,4)

  value = transfer(byte_string(1:4),value)
  print *,"byte_string: value = ",value
  value = transfer(byte_array(1:4),value)
  print *,"byte_array:  value = ",value

  inquire(iolength=n) byte_string
  print *,"byte_string holds ",n," bytes"
  inquire(iolength=n) byte_array
  print *,"byte_array holds ",n," bytes"

end program test_convert

If I understand correctly transfer() should only look at the second parameter
(and the optional size parameter) to decide whether the result should be a
scalar or an array.
At least this is what Metcalf and Reid say in their book fortran90/95
explained. 

However, gfortran seems to look at the rank of the first parameter as well.

best regards,

Jos de Kloe


-- 
           Summary: incorrect conversion from string to integer by convert()
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kloedej at knmi dot nl


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


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

* [Bug fortran/29951] incorrect conversion from string to integer by convert()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
@ 2006-11-23  9:28 ` kloedej at knmi dot nl
  2006-11-23 11:17 ` [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER() burnus at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: kloedej at knmi dot nl @ 2006-11-23  9:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kloedej at knmi dot nl  2006-11-23 09:27 -------
Hi,

a little correction on the just submitted report.
I seem to have mixed up the two cases. The string case fails so it clearly has
nothing to do with the rank of the first parameter to transfer(). 

Jos de Kloe


-- 


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


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

* [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
  2006-11-23  9:28 ` [Bug fortran/29951] " kloedej at knmi dot nl
@ 2006-11-23 11:17 ` burnus at gcc dot gnu dot org
  2006-11-23 11:40 ` burnus at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2006-11-23 11:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from burnus at gcc dot gnu dot org  2006-11-23 11:17 -------
Confirmed.
For "transfer(string, integer)", gfortran's transfer only uses the first
character (byte).
It should use all characters.

-fdump-tree-original:
  value = VIEW_CONVERT_EXPR<int4>(byte_string[1]{lb: 1 sz: 1});

In iresolve.c gfortran only checks whether the source is scalar or an array,
the transfer is then done in gfc_conv_intrinsic_transfer (scalar) or
gfc_conv_intrinsic_array_transfer in trans-intrinsic.c.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2006-11-23 11:17:09
               date|                            |
            Summary|incorrect conversion from   |incorrect conversion from
                   |string to integer by        |string to integer by
                   |convert()                   |TRANSFER()


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


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

* [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
  2006-11-23  9:28 ` [Bug fortran/29951] " kloedej at knmi dot nl
  2006-11-23 11:17 ` [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER() burnus at gcc dot gnu dot org
@ 2006-11-23 11:40 ` burnus at gcc dot gnu dot org
  2006-11-24  3:00 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2006-11-23 11:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2006-11-23 11:39 -------
> In iresolve.c gfortran only checks whether the source is scalar or an array,
This is none sense it actually checks the mold-rank.

The function to modify is gfc_conv_intrinsic_transfer (trans-intrinsic.c);
we somewhere need to obtain for character strings their byte size.
gfc_conv_intrinsic_array_transfer seems to do the right thing.

For "character(len=2) :: byte_array(2)" it works,
for character(len=4) :: byte_array(1)" it does not.


-- 


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


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

* [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (2 preceding siblings ...)
  2006-11-23 11:40 ` burnus at gcc dot gnu dot org
@ 2006-11-24  3:00 ` pinskia at gcc dot gnu dot org
  2006-11-24  8:12 ` kloedej at knmi dot nl
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-24  3:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-11-24 03:00 -------
(In reply to comment #2)
> Confirmed.
> For "transfer(string, integer)", gfortran's transfer only uses the first
> character (byte).
> It should use all characters.
> 
> -fdump-tree-original:
>   value = VIEW_CONVERT_EXPR<int4>(byte_string[1]{lb: 1 sz: 1});

Hmm, I think this is only a bug in 4.3.0 but this was reported against 4.2.0. 
The above VCE is my fault and I have to figure that out but I think there is
something else going wrong if it fails for 4.2.0 since my VCE patch was not
applied there.  I guess I might have revert the VCE patch and create a new one
with memcpy and just hope someone optimizes memcpy better.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (3 preceding siblings ...)
  2006-11-24  3:00 ` pinskia at gcc dot gnu dot org
@ 2006-11-24  8:12 ` kloedej at knmi dot nl
  2006-11-24  8:14 ` [Bug fortran/29951] [4.3 Regression] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: kloedej at knmi dot nl @ 2006-11-24  8:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from kloedej at knmi dot nl  2006-11-24 08:12 -------
Yes, I can confirm the gfortran version used was 4.3.0.
I didn't notice the version number changed when I downoaded the latest version.
Sorry for that.


-- 


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


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

* [Bug fortran/29951] [4.3 Regression] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (4 preceding siblings ...)
  2006-11-24  8:12 ` kloedej at knmi dot nl
@ 2006-11-24  8:14 ` pinskia at gcc dot gnu dot org
  2006-11-24 22:46 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-24  8:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2006-11-24 08:13 -------
Mine to fix then.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pinskia at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
            Summary|incorrect conversion from   |[4.3 Regression] incorrect
                   |string to integer by        |conversion from string to
                   |TRANSFER()                  |integer by TRANSFER()
   Target Milestone|---                         |4.3.0
            Version|4.2.0                       |4.3.0


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


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

* [Bug fortran/29951] [4.3 Regression] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (5 preceding siblings ...)
  2006-11-24  8:14 ` [Bug fortran/29951] [4.3 Regression] " pinskia at gcc dot gnu dot org
@ 2006-11-24 22:46 ` pinskia at gcc dot gnu dot org
  2006-11-25 21:44 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-24 22:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2006-11-24 22:46 -------
Here is the patch which I am testing, it fixes this testcase;
Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c   (revision 119148)
+++ trans-intrinsic.c   (working copy)
@@ -2989,7 +2989,7 @@ gfc_conv_intrinsic_array_transfer (gfc_s


 /* Scalar transfer statement.
-   TRANSFER (source, mold) = VIEW_CONVERT_EXPR<typeof<mold> >source.  */
+   TRANSFER (source, mold) = memcpy(&tmpdecl, &source, size), tmpdecl.  */

 static void
 gfc_conv_intrinsic_transfer (gfc_se * se, gfc_expr * expr)
@@ -2999,6 +2999,7 @@ gfc_conv_intrinsic_transfer (gfc_se * se
   tree type;
   tree ptr;
   gfc_ss *ss;
+  tree tmpdecl, tmp, args;

   /* Get a pointer to the source.  */
   arg = expr->value.function.actual;
@@ -3014,6 +3015,7 @@ gfc_conv_intrinsic_transfer (gfc_se * se

   arg = arg->next;
   type = gfc_typenode_for_spec (&expr->ts);
+
   if (expr->ts.type == BT_CHARACTER)
     {
       ptr = convert (build_pointer_type (type), ptr);
@@ -3026,8 +3028,22 @@ gfc_conv_intrinsic_transfer (gfc_se * se
     }
   else
     {
-      tree tmp = build_fold_indirect_ref (ptr);
-      se->expr = fold_build1 (VIEW_CONVERT_EXPR, type, tmp);
+      tree moldsize;
+      tmpdecl = gfc_create_var (type, "transfer");
+      moldsize = size_in_bytes (type);
+
+      /* Use memcpy to do the transfer.  */
+      tmp = build1 (ADDR_EXPR, build_pointer_type (type), tmpdecl);
+      tmp = fold_convert (pvoid_type_node, tmp);
+      args = gfc_chainon_list (NULL_TREE, tmp);
+      tmp = fold_convert (pvoid_type_node, ptr);
+      args = gfc_chainon_list (args, tmp);
+      args = gfc_chainon_list (args, moldsize);
+      tmp = built_in_decls[BUILT_IN_MEMCPY];
+      tmp = build_function_call_expr (tmp, args);
+      gfc_add_expr_to_block (&se->pre, tmp);
+
+      se->expr = tmpdecl;
     }
 }


-- 


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


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

* [Bug fortran/29951] [4.3 Regression] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (6 preceding siblings ...)
  2006-11-24 22:46 ` pinskia at gcc dot gnu dot org
@ 2006-11-25 21:44 ` pinskia at gcc dot gnu dot org
  2006-11-25 21:45 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-25 21:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pinskia at gcc dot gnu dot org  2006-11-25 21:43 -------
Subject: Bug 29951

Author: pinskia
Date: Sat Nov 25 21:43:48 2006
New Revision: 119211

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119211
Log:
2006-11-25  Andrew Pinski  <pinskia@gmail.com>

        PR fortran/29951
        * trans-intrinsic.c (gfc_conv_intrinsic_transfer): Change to
        call memcpy instead of creating a VIEW_CONVERT_EXRP.

2006-11-25  Andrew Pinski  <pinskia@gmail.com>

        PR fortran/29951
        * gfortran.fortran-torture/execute/transfer2.f90: New test


Added:
    trunk/gcc/testsuite/gfortran.fortran-torture/execute/transfer2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/29951] [4.3 Regression] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (7 preceding siblings ...)
  2006-11-25 21:44 ` pinskia at gcc dot gnu dot org
@ 2006-11-25 21:45 ` pinskia at gcc dot gnu dot org
  2006-11-27  8:22 ` kloedej at knmi dot nl
  2007-01-23  5:15 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-25 21:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pinskia at gcc dot gnu dot org  2006-11-25 21:45 -------
Fixed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug fortran/29951] [4.3 Regression] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (8 preceding siblings ...)
  2006-11-25 21:45 ` pinskia at gcc dot gnu dot org
@ 2006-11-27  8:22 ` kloedej at knmi dot nl
  2007-01-23  5:15 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: kloedej at knmi dot nl @ 2006-11-27  8:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from kloedej at knmi dot nl  2006-11-27 08:21 -------
thanks for your effort to fix this bug!
I can confirm todays binary version, downloaded from
"http://quatramaran.ens.fr/~coudert/gfortran/gfortran-linux.tar.gz
works fine for me.

best regards,

Jos de kloe


-- 


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


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

* [Bug fortran/29951] [4.3 Regression] incorrect conversion from string to integer by TRANSFER()
  2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
                   ` (9 preceding siblings ...)
  2006-11-27  8:22 ` kloedej at knmi dot nl
@ 2007-01-23  5:15 ` pinskia at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-23  5:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from pinskia at gcc dot gnu dot org  2007-01-23 05:15 -------
Subject: Bug 29951

Author: pinskia
Date: Tue Jan 23 05:15:21 2007
New Revision: 121076

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121076
Log:
2007-01-22  Andrew Pinski  <pinskia@gmail.com>

        PR fortran/29951
        * gfortran.fortran-torture/execute/transfer2.f90: New test.

        PR Fortran/29410
        * gfortran.fortran-torture/execute/transfer1.f90: New test.
2007-01-22 Andrew Pinski  <pinskia@gmail.com>

        PR fortran/29951
        * trans-intrinsic.c (gfc_conv_intrinsic_transfer): Change to
        call memcpy instead of creating a VIEW_CONVERT_EXRP.

        PR fortran/29410
        * trans-intrinsic.c (gfc_conv_intrinsic_array_transfer):
        Change over to create VIEW_CONVERT_EXPR instead of using an
        ADDR_EXPR, a cast and then an indirect reference.


Added:
   
branches/gcc-4_2-branch/gcc/testsuite/gfortran.fortran-torture/execute/transfer1.f90
      - copied unchanged from r118186,
trunk/gcc/testsuite/gfortran.fortran-torture/execute/transfer1.f90
   
branches/gcc-4_2-branch/gcc/testsuite/gfortran.fortran-torture/execute/transfer2.f90
      - copied unchanged from r119211,
trunk/gcc/testsuite/gfortran.fortran-torture/execute/transfer2.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/trans-intrinsic.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog


-- 


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


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

end of thread, other threads:[~2007-01-23  5:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-23  9:24 [Bug fortran/29951] New: incorrect conversion from string to integer by convert() kloedej at knmi dot nl
2006-11-23  9:28 ` [Bug fortran/29951] " kloedej at knmi dot nl
2006-11-23 11:17 ` [Bug fortran/29951] incorrect conversion from string to integer by TRANSFER() burnus at gcc dot gnu dot org
2006-11-23 11:40 ` burnus at gcc dot gnu dot org
2006-11-24  3:00 ` pinskia at gcc dot gnu dot org
2006-11-24  8:12 ` kloedej at knmi dot nl
2006-11-24  8:14 ` [Bug fortran/29951] [4.3 Regression] " pinskia at gcc dot gnu dot org
2006-11-24 22:46 ` pinskia at gcc dot gnu dot org
2006-11-25 21:44 ` pinskia at gcc dot gnu dot org
2006-11-25 21:45 ` pinskia at gcc dot gnu dot org
2006-11-27  8:22 ` kloedej at knmi dot nl
2007-01-23  5:15 ` pinskia at gcc dot gnu dot 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).