public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* g77 and valgrind error?
@ 2004-08-06 20:43 bvds
  2004-08-06 20:57 ` Anyone knowlegable about valgrind ? Was: " Toon Moene
  0 siblings, 1 reply; 5+ messages in thread
From: bvds @ 2004-08-06 20:43 UTC (permalink / raw)
  To: gcc-help; +Cc: bvds


I am using valgrind on a g77 program and am getting
some peculiar results:

Cccccccccccccccccccccccccccccccccccccccccc
      program memty
      integer i
      i=360
      call fsub(i)
      end
C
      subroutine fsub(i)
      integer i
      double complex x(i,i)
      x(i,i)=complex(0D0,0D0)
      end
Ccccccccccccccccccccccccccccccccccccccccc

Valgrind gives an error of the form:

==12420== Invalid write of size 8
==12420==    at 0x8048671: fsub_ (memty.f:10)
==12420==    by 0x80486C5: main (../../../../gcc-3.1/libf2c/libF77/main.c:61)
==12420==  Address 0x52BFE8A0 is on thread 1's stack
==12420==
==12420== Invalid write of size 8
==12420==    at 0x8048679: fsub_ (memty.f:10)
==12420==    by 0x80486C5: main (../../../../gcc-3.1/libf2c/libF77/main.c:61)
==12420==  Address 0x52BFE8A8 is on thread 1's stack

Some more info:

bvds> uname -a
Linux bvds 2.4.25 #1 SMP Sat Mar 20 15:34:02 EST 2004 i686 i686 i386 GNU/Linux
bvds> g77 --version
GNU Fortran (GCC) 3.3.2
bvds> valgrind  --version
valgrind-2.1.2

I see the same behavior in valgrind-2.0.0.
This only happens for complex arrays.
if I use the g77 flag -femulate-complex, then there is one error.
(I have also sent this to the valgrind mailing list.)

Any ideas?

Brett van de Sande

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

* Anyone knowlegable about valgrind ? Was: Re: g77 and valgrind error?
  2004-08-06 20:43 g77 and valgrind error? bvds
@ 2004-08-06 20:57 ` Toon Moene
  2004-08-06 22:35   ` bvds
  0 siblings, 1 reply; 5+ messages in thread
From: Toon Moene @ 2004-08-06 20:57 UTC (permalink / raw)
  To: bvds; +Cc: gcc-help

bvds@bvds.geneva.edu wrote:
> I am using valgrind on a g77 program and am getting
> some peculiar results:
> 
> Cccccccccccccccccccccccccccccccccccccccccc
>       program memty
>       integer i
>       i=360
>       call fsub(i)
>       end
> C
>       subroutine fsub(i)
>       integer i
>       double complex x(i,i)
>       x(i,i)=complex(0D0,0D0)
>       end
> Ccccccccccccccccccccccccccccccccccccccccc
> 
> Valgrind gives an error of the form:

I do not know anything about valgrind, but the Fortran code is perfectly 
OK.  It uses an automatic array x in subroutine fsub that is dimensioned 
using the dummy argument i, which is an extension of Fortran 77, but 
allowed in Fortran 90 and supported by g77.

I tried your code using g77-3.3.4 as supplied by Debian on their testing 
platform (up-to-date as of Sunday 1/8/2004) and it performs perfectly.

I'm afraid someone else has to help you here (that's why I changed the 
subject).

Cheers,

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
A maintainer of GNU Fortran 95: http://gcc.gnu.org/fortran/

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

* Re: Anyone knowlegable about valgrind ? Was: Re: g77 and valgrind error?
  2004-08-06 20:57 ` Anyone knowlegable about valgrind ? Was: " Toon Moene
@ 2004-08-06 22:35   ` bvds
  2004-08-06 22:40     ` Toon Moene
  0 siblings, 1 reply; 5+ messages in thread
From: bvds @ 2004-08-06 22:35 UTC (permalink / raw)
  To: toon; +Cc: gcc-help

>
>I do not know anything about valgrind, but the Fortran code is perfectly 
>OK.  It uses an automatic array x in subroutine fsub that is dimensioned 
>using the dummy argument i, which is an extension of Fortran 77, but 
>allowed in Fortran 90 and supported by g77.

Yes, the code itself is OK...
Another detail that I forgot to mention is that the valgrind
error goes away when i=350.  Is there anything about memory
allocation in g77 that would change with increasing i?

I have also put this question to the valgrind people, but
*they* probably don't know much about g77.

BvdS

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

* Re: Anyone knowlegable about valgrind ? Was: Re: g77 and valgrind error?
  2004-08-06 22:35   ` bvds
@ 2004-08-06 22:40     ` Toon Moene
  2004-08-08 17:49       ` bvds
  0 siblings, 1 reply; 5+ messages in thread
From: Toon Moene @ 2004-08-06 22:40 UTC (permalink / raw)
  To: bvds; +Cc: gcc-help

bvds@bvds.geneva.edu wrote:

>>I do not know anything about valgrind, but the Fortran code is perfectly 
>>OK.  It uses an automatic array x in subroutine fsub that is dimensioned 
>>using the dummy argument i, which is an extension of Fortran 77, but 
>>allowed in Fortran 90 and supported by g77.
> 
> Yes, the code itself is OK...
> Another detail that I forgot to mention is that the valgrind
> error goes away when i=350.  Is there anything about memory
> allocation in g77 that would change with increasing i?
> 
> I have also put this question to the valgrind people, but
> *they* probably don't know much about g77.

I wouldn't know why 360 is a "magic number", but g77 doesn't do anything 
but place the automatic array on the stack.  Therefore, we have to deal 
with 16 * 360 * 360 bytes = slightly over 2 megabytes of stack space.

I can't see why this would be a problem (unless other automatic arrays 
are also dimensioned using `i'.

Cheers,

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
A maintainer of GNU Fortran 95: http://gcc.gnu.org/fortran/

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

* Re: Anyone knowlegable about valgrind ? Was: Re: g77 and valgrind error?
  2004-08-06 22:40     ` Toon Moene
@ 2004-08-08 17:49       ` bvds
  0 siblings, 0 replies; 5+ messages in thread
From: bvds @ 2004-08-08 17:49 UTC (permalink / raw)
  To: toon; +Cc: gcc-help

>>
>> ==12420== Invalid write of size 8
>> ==12420==    at 0x8048671: fsub_ (memty.f:10)
>> ==12420==    by 0x80486C5: main (../../../../gcc-3.1/libf2c/libF77/main.c:61)
>> ==12420==  Address 0x52BFE8A0 is on thread 1's stack
>> ==12420==
>> ==12420== Invalid write of size 8
>> ==12420==    at 0x8048679: fsub_ (memty.f:10)
>> ==12420==    by 0x80486C5: main (../../../../gcc-3.1/libf2c/libF77/main.c:61)
>> ==12420==  Address 0x52BFE8A8 is on thread 1's stack
>
>If you run with -v you will see this warning:
>
>==9495== Warning: thread 1 switching stacks?  %esp: 0x52BFEA10 --> 0x52A04610
>
>What's happening is that the very large array is using about 1Mb of
>stack space and that is confusing valgrind into thinking that the
>thread has switched to a different stack so it doesn't mark all that
>space as writable and then you get invalid write warnings.
>
>Tom
>
>--
>Tom Hughes (thh@cyberscience.com)
>Software Engineer, Cyberscience Corporation
>http://www.cyberscience.com/
>
Here is the reply from one of the valgrind people, which 
clears things up a bit.  It is interesting that this *only*
happens for type complex.

Thanks,

Brett van de Sande


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

end of thread, other threads:[~2004-08-07 11:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-06 20:43 g77 and valgrind error? bvds
2004-08-06 20:57 ` Anyone knowlegable about valgrind ? Was: " Toon Moene
2004-08-06 22:35   ` bvds
2004-08-06 22:40     ` Toon Moene
2004-08-08 17:49       ` bvds

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).