public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault
@ 2012-01-23 17:44 burnus at gcc dot gnu.org
  2012-01-28 16:50 ` [Bug fortran/51972] " burnus at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-01-23 17:44 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51972
           Summary: [OOP] ALLOCATE misses memset/calloc, causing segfault
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


Created attachment 26435
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26435
Test case

The test case is a reduced version of chapter07/strategy_surrogate_f2003,
available from http://www.cambridge.org/rouson under "Resources available".

When compiling and running the program, one might get:
  Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
  #6  0x400AC5 in __lorenz_module_MOD___copy_lorenz_module_Lorenz at
test.F90:42
  #7  0x401392 in __runge_kutta_2nd_module_MOD_integrate at test.F90:73
  #8  0x40153F in MAIN__ at test.F90:84


And with valgrind:
  Conditional jump or move depends on uninitialised value(s)
  at 0x400AD8: __lorenz_module_MOD___copy_lorenz_module_Lorenz (test.F90:42)
  by 0x4013B2: __runge_kutta_2nd_module_MOD_integrate (test.F90:73)


The issue is that there is MEMSET or CALLOC missing in "integrate". There is a
call to memset in "constructor" and "assign_lorenz".


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

* [Bug fortran/51972] [OOP] ALLOCATE misses memset/calloc, causing segfault
  2012-01-23 17:44 [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault burnus at gcc dot gnu.org
@ 2012-01-28 16:50 ` burnus at gcc dot gnu.org
  2012-01-28 17:42 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-01-28 16:50 UTC (permalink / raw)
  To: gcc-bugs

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

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> 2012-01-28 15:58:37 UTC ---
The following patch fixes the test case.


However, if one comments the "STOP 'Success'" line, one sees that there is
another bug (double free). The problem is that _copy does not properly do a
deep copy.

Expected: A deep copy of both attractor%state and
attractor%integrand%quadrature.

Currently:

__copy_lorenz_module_Lorenz
{
    *dst = *src;
        dst->integrand = src->integrand;
            __builtin_memcpy (dst->state.data, src->state.data, D.1953 * 4);

Thus, there is no deep copy of "attractor%integrand%quadrature"; thus, both
src->integrand->quadrature->_data and dst->integrand->quadrature->_data point
to the same memory, causing - for the example program - a segfault at the end
of the main program.



--- trans-stmt.c        (Revision 183664)
+++ trans-stmt.c        (Arbeitskopie)
@@ -4953 +4953,2 @@ gfc_trans_allocate (gfc_code * code)
-         if (expr->ts.type == BT_DERIVED &&
expr->ts.u.derived->attr.alloc_comp)
+         if (al->expr->ts.type == BT_DERIVED
+             && expr->ts.u.derived->attr.alloc_comp)


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

* [Bug fortran/51972] [OOP] ALLOCATE misses memset/calloc, causing segfault
  2012-01-23 17:44 [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault burnus at gcc dot gnu.org
  2012-01-28 16:50 ` [Bug fortran/51972] " burnus at gcc dot gnu.org
@ 2012-01-28 17:42 ` burnus at gcc dot gnu.org
  2012-01-28 19:01 ` burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-01-28 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-28 16:57:33 UTC ---
Author: burnus
Date: Sat Jan 28 16:57:28 2012
New Revision: 183668

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183668
Log:
2012-01-28  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51972
        * trans-stmt.c (gfc_trans_allocate): Properly check whether
        we have a BT_CLASS which needs to be memset.

2012-01-28  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51972
        * gfortran.dg/class_allocate_12.f90: New.


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


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

* [Bug fortran/51972] [OOP] ALLOCATE misses memset/calloc, causing segfault
  2012-01-23 17:44 [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault burnus at gcc dot gnu.org
  2012-01-28 16:50 ` [Bug fortran/51972] " burnus at gcc dot gnu.org
  2012-01-28 17:42 ` burnus at gcc dot gnu.org
@ 2012-01-28 19:01 ` burnus at gcc dot gnu.org
  2012-01-29 21:25 ` [Bug fortran/51972] [OOP] Wrong code as _copy does not honor CLASS components burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-01-28 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-28 17:40:23 UTC ---
Simplified test case: The problem is that there is a "CLASS" contained in the
derived type. This is currently not handled at all, but one needs: (a) an
allocation and (b) another _vtab->_copy call.


type t
  integer :: x
end type t
type t2

  class(t), allocatable :: a
end type t2

type(t2) :: one, two

allocate (two%a)
two%a%x = 7890
one = two
if (one%a%x /= 7890) call abort ()
end


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

* [Bug fortran/51972] [OOP] Wrong code as _copy does not honor CLASS components
  2012-01-23 17:44 [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-01-28 19:01 ` burnus at gcc dot gnu.org
@ 2012-01-29 21:25 ` burnus at gcc dot gnu.org
  2012-01-29 21:42 ` burnus at gcc dot gnu.org
  2012-02-05  9:46 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-01-29 21:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-29 20:02:25 UTC ---
Author: burnus
Date: Sun Jan 29 20:02:19 2012
New Revision: 183680

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183680
Log:
2012-01-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51972
        * trans-array.c (structure_alloc_comps): Fix assignment of
        polymorphic components (polymorphic deep copying).

2012-01-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51972
        * gfortran.dg/class_allocate_12.f90: Enable disabled test.
        * gfortran.dg/class_48.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_48.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_allocate_12.f90


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

* [Bug fortran/51972] [OOP] Wrong code as _copy does not honor CLASS components
  2012-01-23 17:44 [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-01-29 21:25 ` [Bug fortran/51972] [OOP] Wrong code as _copy does not honor CLASS components burnus at gcc dot gnu.org
@ 2012-01-29 21:42 ` burnus at gcc dot gnu.org
  2012-02-05  9:46 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-01-29 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-29 20:23:42 UTC ---
FIXED on the 4.7 trunk.


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

* [Bug fortran/51972] [OOP] Wrong code as _copy does not honor CLASS components
  2012-01-23 17:44 [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2012-01-29 21:42 ` burnus at gcc dot gnu.org
@ 2012-02-05  9:46 ` burnus at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-02-05  9:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-02-05 09:46:24 UTC ---
Author: burnus
Date: Sun Feb  5 09:46:20 2012
New Revision: 183904

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183904
Log:
2012-02-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51972
        * gfortran.dg/class_48.f90: Add some further checks.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_48.f90


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

end of thread, other threads:[~2012-02-05  9:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-23 17:44 [Bug fortran/51972] New: [OOP] ALLOCATE misses memset/calloc, causing segfault burnus at gcc dot gnu.org
2012-01-28 16:50 ` [Bug fortran/51972] " burnus at gcc dot gnu.org
2012-01-28 17:42 ` burnus at gcc dot gnu.org
2012-01-28 19:01 ` burnus at gcc dot gnu.org
2012-01-29 21:25 ` [Bug fortran/51972] [OOP] Wrong code as _copy does not honor CLASS components burnus at gcc dot gnu.org
2012-01-29 21:42 ` burnus at gcc dot gnu.org
2012-02-05  9:46 ` 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).