public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/37926]  New: Program gives wrong output (connected to char len)
@ 2008-10-27 10:17 janus at gcc dot gnu dot org
  2008-10-27 22:20 ` [Bug fortran/37926] " burnus at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2008-10-27 10:17 UTC (permalink / raw)
  To: gcc-bugs

Consider the following code:


module m

contains

  pure integer function mysize(a)
    integer,intent(in) :: a(:)
    mysize = size(a)
  end function

end module


program prog

use m
implicit none

character(3) :: str

integer :: i(3) = (/1,2,3/)

str = p(i,mysize)

print *,str,len(str)

contains

  function p(y,asz)
    implicit none
    integer :: y(:)
    interface
      pure integer function asz(c)
        integer,intent(in) :: c(:)
      end function
    end interface
    character(asz(y)) p
    integer i
    do i=1,asz(y)
      print *,y(i),achar(iachar('A')+y(i))
      p(i:i) = achar(iachar('A')+y(i))
    end do
    print *,p,len(p)
  end function

end


Compiling this with GCC trunk rev. 141361 does work, but when running the
produced binary the output is:

           1 B
           2 C
           3 D
 BCD           3
 B             3

The first four lines are ok, but the last one should actually be equal to the
second to last one.

The program does give the expected ouput when the implementation of mysize is
changed such that it always returns a constant (e.g. "3").

Compiling with 4.3.1 gives an ICE.
Compiling with g95 works and gives the right output.


-- 
           Summary: Program gives wrong output (connected to char len)
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
@ 2008-10-27 22:20 ` burnus at gcc dot gnu dot org
  2008-10-28 18:44 ` pault at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-10-27 22:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2008-10-27 22:19 -------
Confirm. Works also with NAG f95 and ifort; does not compile with openf95, ICEs
with sunf95 and gfortran 4.1/4.2.

    D.1627 = mysize (D.1625);
    [...]
    D.1650 = MAX_EXPR <D.1627, 0>;
    p (pstr.23, D.1650, D.1616, mysize);
    D.1632 = MAX_EXPR <D.1627, 0>;
    if (D.1632 > 2) goto <D.1651>; else goto <D.1652>;

I don't understand the dump. Why is D.1627 and not D.1650 used for D.1532? Any
why is there is "D.1650 = MAX_EXPR <D.1627, 0>;" for the result variable. It
probably does not harm, but it does not make sense either. (Still, I don't see
why D.1532 is (presumably) "1" and not "3".)


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |32834
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-10-27 22:19:10
               date|                            |


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
  2008-10-27 22:20 ` [Bug fortran/37926] " burnus at gcc dot gnu dot org
@ 2008-10-28 18:44 ` pault at gcc dot gnu dot org
  2008-11-08 17:52 ` pault at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-10-28 18:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pault at gcc dot gnu dot org  2008-10-28 18:42 -------
(In reply to comment #1)
Tobias,

Isn't the problem the following?

    parm.22.dim[0].lbound = 1;
    parm.22.dim[0].ubound = D.1616;
    parm.22.dim[0].stride = NON_LVALUE_EXPR <D.1622>;
    parm.22.data = (void *) &(*ifm.21)[0];
    parm.22.offset = NON_LVALUE_EXPR <D.1621>;
    D.1623 = _gfortran_internal_pack (&parm.22);  /**** void* result ****/
    D.1625 = mysize (D.1623); /**** mysize expects struct
array1_integer(kind=4) & a   ****/
    D.1627 = MAX_EXPR <D.1625, 0> * 64;
    if (D.1627 < 0)
      {
        _gfortran_runtime_error (&"Attempt to allocate a negative amount of
memory."[1]{lb: 1 sz: 1});
      }
    D.1628 = __builtin_malloc (MAX_EXPR <(integer(kind=8)) D.1627, 1>);
    if (D.1628 == 0B)
      {
        _gfortran_os_error (&"Memory allocation failed"[1]{lb: 1 sz: 1});
      }
    pstr.23 = (character(kind=1)[1:MAX_EXPR <D.1625, 0>] *) D.1628;
    p (pstr.23, MAX_EXPR <D.1625, 0>, D.1614, mysize);


Thus it's the internal_pack that does this in.

Paul


-- 


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
  2008-10-27 22:20 ` [Bug fortran/37926] " burnus at gcc dot gnu dot org
  2008-10-28 18:44 ` pault at gcc dot gnu dot org
@ 2008-11-08 17:52 ` pault at gcc dot gnu dot org
  2008-11-14 19:02 ` pault at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-08 17:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pault at gcc dot gnu dot org  2008-11-08 17:50 -------
(In reply to comment #2)
> (In reply to comment #1)

...and this comes about because gfc_apply_interface_mapping is failing to add
the formal arguments to the new symbol used to evaluate expression for asz(y). 
I cannot see why right now :-(

Paul


-- 


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2008-11-08 17:52 ` pault at gcc dot gnu dot org
@ 2008-11-14 19:02 ` pault at gcc dot gnu dot org
  2008-11-15  5:58 ` pault at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-14 19:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pault at gcc dot gnu dot org  2008-11-14 19:00 -------
A fix is regtesting right now.

Paul


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pault at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-10-27 22:19:10         |2008-11-14 19:00:42
               date|                            |


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2008-11-14 19:02 ` pault at gcc dot gnu dot org
@ 2008-11-15  5:58 ` pault at gcc dot gnu dot org
  2008-11-15 17:29 ` pault at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-15  5:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pault at gcc dot gnu dot org  2008-11-15 05:57 -------
Created an attachment (id=16680)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16680&action=view)
A prototype patch

This fixes the problem but causes a couple of regressions - eg. mapping_1.f90

This clearly demonstrates that the replacement function needs a formal arglist
to work correctly.

Paul


-- 


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2008-11-15  5:58 ` pault at gcc dot gnu dot org
@ 2008-11-15 17:29 ` pault at gcc dot gnu dot org
  2008-11-16 12:03 ` pault at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-15 17:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pault at gcc dot gnu dot org  2008-11-15 17:27 -------
Subject: Bug 37926

Author: pault
Date: Sat Nov 15 17:26:13 2008
New Revision: 141890

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

        PR fortran/37926
        * trans-expr.c (gfc_add_interface_mapping): Transfer the formal
        arglist and the always_explicit attribute if the dummy arg is a
        procedure.

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

        PR fortran/37926
        * gfortran.dg/dummy_procedure_3.f90: New test.

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


-- 


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2008-11-15 17:29 ` pault at gcc dot gnu dot org
@ 2008-11-16 12:03 ` pault at gcc dot gnu dot org
  2008-11-24 19:21 ` pault at gcc dot gnu dot org
  2008-11-24 19:22 ` pault at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-16 12:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pault at gcc dot gnu dot org  2008-11-16 12:02 -------
Subject: Bug 37926

Author: pault
Date: Sun Nov 16 12:00:44 2008
New Revision: 141914

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

        PR fortran/37926
        * trans-expr.c (gfc_free_interface_mapping): Null sym->formal
        (gfc_add_interface_mapping): Copy the pointer to the formal
        arglist, rather than using copy_formal_args.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c


-- 


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2008-11-16 12:03 ` pault at gcc dot gnu dot org
@ 2008-11-24 19:21 ` pault at gcc dot gnu dot org
  2008-11-24 19:22 ` pault at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-24 19:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pault at gcc dot gnu dot org  2008-11-24 19:20 -------
Subject: Bug 37926

Author: pault
Date: Mon Nov 24 19:18:39 2008
New Revision: 142171

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

        PR fortran/37926
        * trans-expr.c (gfc_free_interface_mapping): Null sym->formal
        (gfc_add_interface_mapping): Copy the pointer to the formal
        arglist and set attr.always_explicit if this is a procedure.

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

        PR fortran/37926
        * gfortran.dg/dummy_procedure_3.f90: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/dummy_procedure_3.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/37926] Program gives wrong output (connected to char len)
  2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2008-11-24 19:21 ` pault at gcc dot gnu dot org
@ 2008-11-24 19:22 ` pault at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-24 19:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pault at gcc dot gnu dot org  2008-11-24 19:20 -------
Fixed on trunk and 4.3.

Thanks for the report.

Paul


-- 

pault at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2008-11-24 19:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-27 10:17 [Bug fortran/37926] New: Program gives wrong output (connected to char len) janus at gcc dot gnu dot org
2008-10-27 22:20 ` [Bug fortran/37926] " burnus at gcc dot gnu dot org
2008-10-28 18:44 ` pault at gcc dot gnu dot org
2008-11-08 17:52 ` pault at gcc dot gnu dot org
2008-11-14 19:02 ` pault at gcc dot gnu dot org
2008-11-15  5:58 ` pault at gcc dot gnu dot org
2008-11-15 17:29 ` pault at gcc dot gnu dot org
2008-11-16 12:03 ` pault at gcc dot gnu dot org
2008-11-24 19:21 ` pault at gcc dot gnu dot org
2008-11-24 19:22 ` pault 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).