public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53296] New: Segfault on non-constant character array constructor containing kind spec
@ 2012-05-09 15:53 gccbgz.lionm at xoxy dot net
  2012-05-09 17:24 ` [Bug fortran/53296] " burnus at gcc dot gnu.org
  2012-05-10 11:29 ` burnus at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gccbgz.lionm at xoxy dot net @ 2012-05-09 15:53 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53296
           Summary: Segfault on non-constant character array constructor
                    containing kind spec
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gccbgz.lionm@xoxy.net


Created attachment 27360
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27360
source raising the segfault

Executing the binary compiled from attached source prints:

 size          78
 arr: ABCDEGHIJ 
 size           1
Speicherzugriffsfehler (Speicherabzug geschrieben)

Besides the segfault, the array size should not change.

This is not reproducable when replacing the character(*)-type entities by
integer(INT64) nor when omitting the function call in the constructor.


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

* [Bug fortran/53296] Segfault on non-constant character array constructor containing kind spec
  2012-05-09 15:53 [Bug fortran/53296] New: Segfault on non-constant character array constructor containing kind spec gccbgz.lionm at xoxy dot net
@ 2012-05-09 17:24 ` burnus at gcc dot gnu.org
  2012-05-10 11:29 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-09 17:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |burnus at gcc dot gnu.org
      Known to fail|                            |4.6.1, 4.8.0

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-05-09 17:22:43 UTC ---
It also doesn't segfault if one replaces the call by:

  call rou( [character(len=120) :: "123",uCase("abcde"),uCase("ghij")])

Namely: adding as first item in the constructor list a string literal (which by
construction has a known length).

According to VALGRIND, the problem is an
   Invalid free() / delete / delete[] / realloc()
in line 10 or, if commented, in line 9. Line 9 is the "call rou" line.


With ifort 12.1, the programs seems to work while with cryftn it fails at run
time with an illegal instruction. In any case, the program looks valid to me.


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

* [Bug fortran/53296] Segfault on non-constant character array constructor containing kind spec
  2012-05-09 15:53 [Bug fortran/53296] New: Segfault on non-constant character array constructor containing kind spec gccbgz.lionm at xoxy dot net
  2012-05-09 17:24 ` [Bug fortran/53296] " burnus at gcc dot gnu.org
@ 2012-05-10 11:29 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-10 11:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-05-10 10:35:22 UTC ---
Simplified program.

* As is, it prints 128
* Without  "txt", it prints 5 and segfaults
* Without  character(len=128) :: "txt",   it prints 5 and works

Thus, the extension to 128 characters does not properly work in the case of
having no character literal. That matches what is in the code:

          character(kind=1) A.16[2][1:5];
vs.
          character(kind=1) A.15[3][1:128];


I have not looked through the source code, but the first place, where
constructors string lengths are handled is array.c's
gfc_resolve_character_array_constructor. I don't quickly see whether it does so
correctly or not. If it does, the failure must be later.

It might be that in that function, the "txt" is correctly extended and padded
to len=128 - and that then everything is later handled correctly because the
first element has the right size?


program charArrErr
  implicit none
  call rou([character(len=128) :: "txt", uCase("abcde"),uCase("ghij_")])
contains
  subroutine rou(arr)
    implicit none
    character(*),intent(in) :: arr(:)
    print *, len(arr)
  end subroutine

  function uCase(str)
    implicit none
    character(*), intent(in) :: str
    character(len(str)) :: uCase
    uCase=str
  end function uCase
end program charArrErr


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

end of thread, other threads:[~2012-05-10 10:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-09 15:53 [Bug fortran/53296] New: Segfault on non-constant character array constructor containing kind spec gccbgz.lionm at xoxy dot net
2012-05-09 17:24 ` [Bug fortran/53296] " burnus at gcc dot gnu.org
2012-05-10 11:29 ` 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).