public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/49993] New: arrays declared as parameter are not allocated in read-only memory
@ 2011-08-05 17:32 arnaud02 at users dot sourceforge.net
  2011-08-08 10:28 ` [Bug fortran/49993] " arnaud02 at users dot sourceforge.net
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: arnaud02 at users dot sourceforge.net @ 2011-08-05 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: arrays declared as parameter are not allocated in
                    read-only memory
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: arnaud02@users.sourceforge.net


Consider the following illegal program which contains an attempt to modify a
scalar variable declared as parameter:
      subroutine a1(ia)
      integer :: ia
      ia=1
      end subroutine
      subroutine a2()
      integer, parameter :: ia = 2
      call a1(ia)
      end subroutine
      program m
      call a2()
      end program
As "ia" is allocated in the "rodata" section, this leads sensibly to a
"segmentation fault".

Consider now a similar program that with an array instead of a scalar:
      subroutine a1(ia)
      integer :: ia
      ia=1
      end subroutine
      subroutine a2()
      integer, parameter :: ia(1) = (/ 2 /)
      call a1(ia(1))
      end subroutine
      program m
      call a2()
      end program
This time, now "segmentation fault" is generated because array "ia" is not
allocated in the "rodata" section. 
Could gfortran be modified to allocate arrays declared in parameter in the
rodata section? This would help detecting bugs and may even provide a slight
performance and code size advantage.


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

* [Bug fortran/49993] arrays declared as parameter are not allocated in read-only memory
  2011-08-05 17:32 [Bug fortran/49993] New: arrays declared as parameter are not allocated in read-only memory arnaud02 at users dot sourceforge.net
@ 2011-08-08 10:28 ` arnaud02 at users dot sourceforge.net
  2011-08-08 15:05 ` kargl at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: arnaud02 at users dot sourceforge.net @ 2011-08-08 10:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Arnaud Desitter <arnaud02 at users dot sourceforge.net> 2011-08-08 10:28:27 UTC ---
The equivalent "C" program results in the expected "segmentation fault".

void a1(int *ia) {
  *ia = 1;
}
void a2(void) {
  static const int ia[] = { 2 };
  a1(ia);
}
int main(void) {
  a2();
  return 0;
}


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

* [Bug fortran/49993] arrays declared as parameter are not allocated in read-only memory
  2011-08-05 17:32 [Bug fortran/49993] New: arrays declared as parameter are not allocated in read-only memory arnaud02 at users dot sourceforge.net
  2011-08-08 10:28 ` [Bug fortran/49993] " arnaud02 at users dot sourceforge.net
@ 2011-08-08 15:05 ` kargl at gcc dot gnu.org
  2011-08-09 20:25 ` arnaud02 at users dot sourceforge.net
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu.org @ 2011-08-08 15:05 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #2 from kargl at gcc dot gnu.org 2011-08-08 15:05:10 UTC ---
(In reply to comment #1)
> The equivalent "C" program results in the expected "segmentation fault".
> 
> void a1(int *ia) {
>   *ia = 1;
> }
> void a2(void) {
>   static const int ia[] = { 2 };
>   a1(ia);
> }
> int main(void) {
>   a2();
>   return 0;
> }

The programs aren't equivalent.  You need to change a2 to

void a2(void) {
  static int ia[] = { 2 };
  a1(ia);
}

then the programs are equivalent.


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

* [Bug fortran/49993] arrays declared as parameter are not allocated in read-only memory
  2011-08-05 17:32 [Bug fortran/49993] New: arrays declared as parameter are not allocated in read-only memory arnaud02 at users dot sourceforge.net
  2011-08-08 10:28 ` [Bug fortran/49993] " arnaud02 at users dot sourceforge.net
  2011-08-08 15:05 ` kargl at gcc dot gnu.org
@ 2011-08-09 20:25 ` arnaud02 at users dot sourceforge.net
  2011-11-04 10:35 ` arnaud02 at users dot sourceforge.net
  2011-11-04 11:00 ` burnus at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: arnaud02 at users dot sourceforge.net @ 2011-08-09 20:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Arnaud Desitter <arnaud02 at users dot sourceforge.net> 2011-08-09 20:24:59 UTC ---
"static int ia[] = { 2 };" is equivalent to "integer, save :: ia(1) = (/ 2 /)".
Anyway, the C example was there to show that allocating a constant array in the
rodata section is possible.


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

* [Bug fortran/49993] arrays declared as parameter are not allocated in read-only memory
  2011-08-05 17:32 [Bug fortran/49993] New: arrays declared as parameter are not allocated in read-only memory arnaud02 at users dot sourceforge.net
                   ` (2 preceding siblings ...)
  2011-08-09 20:25 ` arnaud02 at users dot sourceforge.net
@ 2011-11-04 10:35 ` arnaud02 at users dot sourceforge.net
  2011-11-04 11:00 ` burnus at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: arnaud02 at users dot sourceforge.net @ 2011-11-04 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

Arnaud Desitter <arnaud02 at users dot sourceforge.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |50960

--- Comment #4 from Arnaud Desitter <arnaud02 at users dot sourceforge.net> 2011-11-04 10:34:18 UTC ---
This has probably been fixed by revision 180878 (PR fortran/50960).


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

* [Bug fortran/49993] arrays declared as parameter are not allocated in read-only memory
  2011-08-05 17:32 [Bug fortran/49993] New: arrays declared as parameter are not allocated in read-only memory arnaud02 at users dot sourceforge.net
                   ` (3 preceding siblings ...)
  2011-11-04 10:35 ` arnaud02 at users dot sourceforge.net
@ 2011-11-04 11:00 ` burnus at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-11-04 11:00 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

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

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-04 10:59:35 UTC ---
(In reply to comment #0)
> Could gfortran be modified to allocate arrays declared in parameter in the
> rodata section? This would help detecting bugs and may even provide a slight
> performance and code size advantage.

A belated thanks for the bugreport!


(In reply to comment #4)
> This has probably been fixed by revision 180878 (PR fortran/50960).

Looks like. I get the wished-for segfault for the second program of comment 0.

The assembler also looks OK, but I have to admit that I am not really an
assembler person.

For the simpler
  module m
    integer, parameter :: xxx(*) = [1,2,3,4]
  end module m
one gets now the following:
        .globl  __m_MOD_xxx
        .section        .rodata
        .align 16
        .type   __m_MOD_xxx, @object
        .size   __m_MOD_xxx, 16
__m_MOD_xxx:
        .long   1
        .long   2
        .long   3
        .long   4

Hence, I indeed see the .rodata for the correct variable.

I close this bug now - please reopen if something is still wrong.


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

end of thread, other threads:[~2011-11-04 11:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-05 17:32 [Bug fortran/49993] New: arrays declared as parameter are not allocated in read-only memory arnaud02 at users dot sourceforge.net
2011-08-08 10:28 ` [Bug fortran/49993] " arnaud02 at users dot sourceforge.net
2011-08-08 15:05 ` kargl at gcc dot gnu.org
2011-08-09 20:25 ` arnaud02 at users dot sourceforge.net
2011-11-04 10:35 ` arnaud02 at users dot sourceforge.net
2011-11-04 11:00 ` burnus 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).