public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) /  -fno-align-commons
@ 2013-02-12  9:51 burnus at gcc dot gnu.org
  2013-02-12  9:52 ` [Bug fortran/56293] " burnus at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-12  9:51 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56293
           Summary: I/O: Segfault in write_float when trying to print a
                    not-word-aligned REAL(16) /  -fno-align-commons
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: jb@gcc.gnu.org, jvdelisle@gcc.gnu.org


Reported by Maciej Skrzypek at
http://gcc.gnu.org/ml/fortran/2013-02/msg00058.html

In the following code, "p" is not aligned; using it fails in GCC 4.8 with a
segfault in

#0  0x00007ffff7ba5e16 in write_float (dtp=dtp@entry=0x7fffffffde40,
f=f@entry=0x7fffffffdd70, source=source@entry=0x601084 <sss_+4> "",
len=len@entry=16, 
    comp_d=comp_d@entry=1) at libgfortran/io/write_float.def:1259
#1  0x00007ffff7ba8365 in _gfortrani_write_real (dtp=dtp@entry=0x7fffffffde40,
source=source@entry=0x601084 <sss_+4> "", length=length@entry=16)
    at libgfortran/io/write.c:1470
#2  0x00007ffff7ba8dcf in list_formatted_write_scalar (size=16, kind=16,
p=0x601084 <sss_+4>, type=BT_REAL, dtp=0x7fffffffde40) at
libgfortran/io/write.c:1571
#3  _gfortrani_list_formatted_write (dtp=0x7fffffffde40, type=BT_REAL,
p=<optimized out>, kind=16, size=16, nelems=1) at libgfortran/io/write.c:1599



Compile with:  -fno-align-commons

      program main
      real(16) p
      integer i
      common/sss/ i, p
      print*, p
      end


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

* [Bug fortran/56293] I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
@ 2013-02-12  9:52 ` burnus at gcc dot gnu.org
  2013-02-12 10:23 ` tobi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-12  9:52 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-02-12 09:52:09 UTC ---
Ditto for READ:

0x00007ffff7b9b55f in _gfortrani_convert_real (dtp=dtp@entry=0x7fffffffde40,
dest=dest@entry=0x601084 <sss_+4>, buffer=0x604fb0 "445.54",
length=length@entry=16)  at libgfortran/io/read.c:155


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

* [Bug fortran/56293] I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
  2013-02-12  9:52 ` [Bug fortran/56293] " burnus at gcc dot gnu.org
@ 2013-02-12 10:23 ` tobi at gcc dot gnu.org
  2013-02-12 12:35 ` [Bug fortran/56293] Segfault when trying to access pass-by-reference value of " burnus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tobi at gcc dot gnu.org @ 2013-02-12 10:23 UTC (permalink / raw)
  To: gcc-bugs


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

Tobias Schlüter <tobi at gcc dot gnu.org> changed:

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

--- Comment #2 from Tobias Schlüter <tobi at gcc dot gnu.org> 2013-02-12 10:23:32 UTC ---
This is valid behavior, -fno-align-common is documented to potentially break
stuff (though the documentation could be more explicit on that).


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

* [Bug fortran/56293] Segfault when trying to access pass-by-reference value of a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
  2013-02-12  9:52 ` [Bug fortran/56293] " burnus at gcc dot gnu.org
  2013-02-12 10:23 ` tobi at gcc dot gnu.org
@ 2013-02-12 12:35 ` burnus at gcc dot gnu.org
  2013-02-12 12:40 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-12 12:35 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|I/O: Segfault in            |Segfault when trying to
                   |write_float when trying to  |access pass-by-reference
                   |print a not-word-aligned    |value of a not-word-aligned
                   |REAL(16) /                  |REAL(16) /
                   |-fno-align-commons          |-fno-align-commons

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-02-12 12:35:19 UTC ---
Also occurs if one calls ("call foo(p)"):
      subroutine foo(x)
        real(16) :: x, y
        y = x  ! FAILS HERE
        ! print *, y
      end subroutine foo
instead of "print *, p".


The bug is probably somewhere in gcc/fortran/trans-common.c's. For instance at
build_common_decl, which uses:

      if (!com->is_bind_c)
        DECL_ALIGN (decl) = BIGGEST_ALIGNMENT;

or/and in "build_field", which has:

  known_align = (offset & -offset) * BITS_PER_UNIT;
  if (known_align == 0 || known_align > BIGGEST_ALIGNMENT)
    known_align = BIGGEST_ALIGNMENT;

  desired_align = update_alignment_for_field (rli, field, known_align);
  if (desired_align > known_align)
       (field) = 1;

or …


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

* [Bug fortran/56293] Segfault when trying to access pass-by-reference value of a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-02-12 12:35 ` [Bug fortran/56293] Segfault when trying to access pass-by-reference value of " burnus at gcc dot gnu.org
@ 2013-02-12 12:40 ` rguenth at gcc dot gnu.org
  2013-02-12 13:07 ` burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-02-12 12:40 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> 2013-02-12 12:39:55 UTC ---
(In reply to comment #3)
> Also occurs if one calls ("call foo(p)"):
>       subroutine foo(x)
>         real(16) :: x, y
>         y = x  ! FAILS HERE
>         ! print *, y
>       end subroutine foo
> instead of "print *, p".
> 
> 
> The bug is probably somewhere in gcc/fortran/trans-common.c's. For instance at
> build_common_decl, which uses:
> 
>       if (!com->is_bind_c)
>         DECL_ALIGN (decl) = BIGGEST_ALIGNMENT;
> 
> or/and in "build_field", which has:
> 
>   known_align = (offset & -offset) * BITS_PER_UNIT;
>   if (known_align == 0 || known_align > BIGGEST_ALIGNMENT)
>     known_align = BIGGEST_ALIGNMENT;
> 
>   desired_align = update_alignment_for_field (rli, field, known_align);
>   if (desired_align > known_align)
>        (field) = 1;
> 
> or …

The problem is that you are in no way dealing with the interface
mismatches in a correct way.  Not that I think you can.

I suggest to remove -fno-align-commons.

Or is there a fortran way to say that

       subroutine foo(x)
         real(16) :: x, y

may receive an unaligned x?

It seems to me that with an -fno-align-commons common you cannot do very
much.  You'd have to make sure to always access it though the common
and never pass pieces of it to another function (maybe the frontend could
warn about this).  Can you specify -fno-align-commons per common block?


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

* [Bug fortran/56293] Segfault when trying to access pass-by-reference value of a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2013-02-12 12:40 ` rguenth at gcc dot gnu.org
@ 2013-02-12 13:07 ` burnus at gcc dot gnu.org
  2013-03-10 15:32 ` tkoenig at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-02-12 13:07 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-02-12 13:07:10 UTC ---
Some tests with ifort, which by default uses unaligned commons: The first test
case works, i.e. I/O with the unaligned "p" works. However, if one calls a user
procedure ("call foo(p)"), it segfaults.


Possible solutions:

a) Copy-in/copy-out around procedure calls - which is fun with large arrays.

b) Require the user to annotate the functions to possibly accept unaligned
input – or do so automatically. (With all the fun of third-party libraries like
LAPACK, BLAS, ...)

c) Simply deprecating the  -fno-align-commons flag, improving the wording of
the diagnostic and the description in the man page.

Somehow, I am in favour of (c).

The question is also whether one can construct a fully standard-conform example
which fails without -fno-align-commons – and whether some real-world code uses
COMMON in a way that would fails with alignments/padding.


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

* [Bug fortran/56293] Segfault when trying to access pass-by-reference value of a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2013-02-12 13:07 ` burnus at gcc dot gnu.org
@ 2013-03-10 15:32 ` tkoenig at gcc dot gnu.org
  2013-03-11  0:16 ` tobi at gcc dot gnu.org
  2014-01-07 14:04 ` dominiq at lps dot ens.fr
  7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2013-03-10 15:32 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #6 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2013-03-10 15:32:14 UTC ---

> The question is also whether one can construct a fully standard-conform example
> which fails without -fno-align-commons – and whether some real-world code uses
> COMMON in a way that would fails with alignments/padding.

      program main
      real a,f1,f2,d
      common /foo/ a,f1,f2,d
      a = 1.0
      d = 1.0
      call s1
      end
      subroutine s1
      real a,b
      double precision d
      common /foo/ a,d,b
      print *,a
      print *,b
      end


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

* [Bug fortran/56293] Segfault when trying to access pass-by-reference value of a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2013-03-10 15:32 ` tkoenig at gcc dot gnu.org
@ 2013-03-11  0:16 ` tobi at gcc dot gnu.org
  2014-01-07 14:04 ` dominiq at lps dot ens.fr
  7 siblings, 0 replies; 9+ messages in thread
From: tobi at gcc dot gnu.org @ 2013-03-11  0:16 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from Tobias Schlüter <tobi at gcc dot gnu.org> 2013-03-11 00:15:43 UTC ---
(In reply to comment #6)
> > The question is also whether one can construct a fully standard-conform example
> > which fails without -fno-align-commons – and whether some real-world code uses
> > COMMON in a way that would fails with alignments/padding.
> 
>       program main
>       real a,f1,f2,d
>       common /foo/ a,f1,f2,d
>       a = 1.0
>       d = 1.0
>       call s1
>       end
>       subroutine s1
>       real a,b
>       double precision d
>       common /foo/ a,d,b
>       print *,a
>       print *,b
>       end

That's not valid.  I'm looking at the F95 working draft:
according to note 5.33
"""Association in different scoping units between objects of default type,
objects of double precision real type, and sequence structures is permitted
according to the rules for equivalence objects (5.5.1)."""

and in 5.5.1. we have
"""If an equivalence-object is of type default integer, default real, double
precision real, default complex, default logical, or numeric sequence type, all
of the objects in the equivalence set shall be of these types."""


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

* [Bug fortran/56293] Segfault when trying to access pass-by-reference value of a not-word-aligned REAL(16) /  -fno-align-commons
  2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2013-03-11  0:16 ` tobi at gcc dot gnu.org
@ 2014-01-07 14:04 ` dominiq at lps dot ens.fr
  7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-01-07 14:04 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2014-01-07
     Ever confirmed|0                           |1

--- Comment #8 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> c) Simply deprecating the  -fno-align-commons flag, improving the wording 
> of the diagnostic and the description in the man page.
>
> Somehow, I am in favour of (c).

Me too.


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

end of thread, other threads:[~2014-01-07 14:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-12  9:51 [Bug fortran/56293] New: I/O: Segfault in write_float when trying to print a not-word-aligned REAL(16) / -fno-align-commons burnus at gcc dot gnu.org
2013-02-12  9:52 ` [Bug fortran/56293] " burnus at gcc dot gnu.org
2013-02-12 10:23 ` tobi at gcc dot gnu.org
2013-02-12 12:35 ` [Bug fortran/56293] Segfault when trying to access pass-by-reference value of " burnus at gcc dot gnu.org
2013-02-12 12:40 ` rguenth at gcc dot gnu.org
2013-02-12 13:07 ` burnus at gcc dot gnu.org
2013-03-10 15:32 ` tkoenig at gcc dot gnu.org
2013-03-11  0:16 ` tobi at gcc dot gnu.org
2014-01-07 14:04 ` dominiq at lps dot ens.fr

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