public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/45004]  New: [OOP] Segfault with allocatable scalars and move_alloc
@ 2010-07-20 12:52 sfilippone at uniroma2 dot it
  2010-07-20 12:53 ` [Bug fortran/45004] " sfilippone at uniroma2 dot it
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: sfilippone at uniroma2 dot it @ 2010-07-20 12:52 UTC (permalink / raw)
  To: gcc-bugs

I keep getting segfaults at (more or less) random places. Moreover, the
segfaults on the same code are different on X86_64 from i686 (in the latter
case, they are less frequent). 
This is probably due to move_alloc not being fully/correctly implemented. 
I see nothing wrong with the attached code (indeed, the library from which this
is extracted compiles and runs fine with NAG and XLF). 

[sfilippo@donald bug18]$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/gnu46/libexec/gcc/x86_64-unknown-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --prefix=/usr/local/gnu46
--enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.6.0 20100715 (experimental) (GCC) 
[sfilippo@donald bug18]$ gfortran -o bug18 bug18.f03  
[sfilippo@donald bug18]$ ./bug18
 Ok on move target
 Ok on move source
 Test completed 
Segmentation fault


-- 
           Summary: [OOP] Segfault with allocatable scalars and move_alloc
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sfilippone at uniroma2 dot it
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug fortran/45004] [OOP] Segfault with allocatable scalars and move_alloc
  2010-07-20 12:52 [Bug fortran/45004] New: [OOP] Segfault with allocatable scalars and move_alloc sfilippone at uniroma2 dot it
@ 2010-07-20 12:53 ` sfilippone at uniroma2 dot it
  2010-07-22 21:22 ` janus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: sfilippone at uniroma2 dot it @ 2010-07-20 12:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from sfilippone at uniroma2 dot it  2010-07-20 12:52 -------
Created an attachment (id=21263)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21263&action=view)
test case


-- 


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


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

* [Bug fortran/45004] [OOP] Segfault with allocatable scalars and move_alloc
  2010-07-20 12:52 [Bug fortran/45004] New: [OOP] Segfault with allocatable scalars and move_alloc sfilippone at uniroma2 dot it
  2010-07-20 12:53 ` [Bug fortran/45004] " sfilippone at uniroma2 dot it
@ 2010-07-22 21:22 ` janus at gcc dot gnu dot org
  2010-07-22 21:45 ` janus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-07-22 21:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from janus at gcc dot gnu dot org  2010-07-22 21:21 -------
Reduced test case with the same output:

program bug18

  type foo
    integer :: i
  end type foo

  type bar
    class(foo), allocatable :: bf
  end type bar

  class(foo), allocatable :: afab
  type(bar) :: bb

  allocate(foo :: afab)
  call move_alloc(afab, bb%bf)
  if (allocated(bb%bf)) then
    write(0,*) 'Ok on move target'
  else
    write(0,*) 'Bad move target'
  endif
  if (.not.allocated(afab)) then
    write(0,*) 'Ok on move source'
  else
    write(0,*) 'Bad move source'
  endif
  write(0,*) 'Test completed '

end program bug18


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-07-22 21:21:57
               date|                            |


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


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

* [Bug fortran/45004] [OOP] Segfault with allocatable scalars and move_alloc
  2010-07-20 12:52 [Bug fortran/45004] New: [OOP] Segfault with allocatable scalars and move_alloc sfilippone at uniroma2 dot it
  2010-07-20 12:53 ` [Bug fortran/45004] " sfilippone at uniroma2 dot it
  2010-07-22 21:22 ` janus at gcc dot gnu dot org
@ 2010-07-22 21:45 ` janus at gcc dot gnu dot org
  2010-07-23 16:20 ` janus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-07-22 21:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from janus at gcc dot gnu dot org  2010-07-22 21:44 -------
Here is an even more elementary example which shows that there is a problem for
allocatable scalars, already without any polymorphic variables:

  implicit none
  integer, allocatable :: afab1,afab2
  allocate(afab1)
  afab1 = irand()
  print *,afab1
  call move_alloc(afab1, afab2)
  print *,afab2
  print *,allocated(afab2)
  print *,allocated(afab1)
end


This directly segfaults on move_alloc:

       16807
Segmentation fault


The problem is that _gfortran_move_alloc expects two array descriptors as
arguments, but allocatable scalars have none. Therefore we probably need
something like '_gfortran_move_alloc_scalar'.

For classes we will probably have to add a reference to the $data component
before passing them to move_alloc.


-- 


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


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

* [Bug fortran/45004] [OOP] Segfault with allocatable scalars and move_alloc
  2010-07-20 12:52 [Bug fortran/45004] New: [OOP] Segfault with allocatable scalars and move_alloc sfilippone at uniroma2 dot it
                   ` (2 preceding siblings ...)
  2010-07-22 21:45 ` janus at gcc dot gnu dot org
@ 2010-07-23 16:20 ` janus at gcc dot gnu dot org
  2010-07-29 18:15 ` janus at gcc dot gnu dot org
  2010-07-29 18:18 ` janus at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-07-23 16:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from janus at gcc dot gnu dot org  2010-07-23 16:19 -------
Here is a draft patch which deals with allocatable scalars:

Index: gcc/fortran/trans.c
===================================================================
--- gcc/fortran/trans.c (revision 162448)
+++ gcc/fortran/trans.c (working copy)
@@ -1157,8 +1157,27 @@ trans_code (gfc_code * code, tree cond)
            if (code->resolved_isym
                && code->resolved_isym->id == GFC_ISYM_MVBITS)
              is_mvbits = true;
-           res = gfc_trans_call (code, is_mvbits, NULL_TREE,
-                                 NULL_TREE, false);
+           if (code->resolved_isym
+               && code->resolved_isym->id == GFC_ISYM_MOVE_ALLOC
+               && code->ext.actual->expr->rank == 0)
+             {
+               gfc_expr *from, *to;
+               stmtblock_t block;
+               tree tmp;
+               
+               from = code->ext.actual->expr;
+               to = code->ext.actual->next->expr;
+               
+               gfc_start_block (&block);
+               tmp = gfc_trans_pointer_assignment (to, from);
+               gfc_add_expr_to_block (&block, tmp);
+               tmp = gfc_trans_pointer_assignment (from, gfc_get_null_expr
(NULL));
+               gfc_add_expr_to_block (&block, tmp);
+               res = gfc_finish_block (&block);
+             }
+           else
+             res = gfc_trans_call (code, is_mvbits, NULL_TREE,
+                                   NULL_TREE, false);
          }
          break;



-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |janus at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2010-07-22 21:21:57         |2010-07-23 16:19:41
               date|                            |


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


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

* [Bug fortran/45004] [OOP] Segfault with allocatable scalars and move_alloc
  2010-07-20 12:52 [Bug fortran/45004] New: [OOP] Segfault with allocatable scalars and move_alloc sfilippone at uniroma2 dot it
                   ` (3 preceding siblings ...)
  2010-07-23 16:20 ` janus at gcc dot gnu dot org
@ 2010-07-29 18:15 ` janus at gcc dot gnu dot org
  2010-07-29 18:18 ` janus at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-07-29 18:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from janus at gcc dot gnu dot org  2010-07-29 18:14 -------
Subject: Bug 45004

Author: janus
Date: Thu Jul 29 18:14:16 2010
New Revision: 162688

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162688
Log:
2010-07-29  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/45004
        * trans-stmt.h (gfc_trans_class_init_assign): New prototype.
        (gfc_trans_class_assign): Modified prototype.
        * trans.h (gfc_conv_intrinsic_move_alloc): New prototype.
        * trans-expr.c (gfc_trans_class_init_assign): Split off from ...
        (gfc_trans_class_assign): ... here. Modified actual arguments.
        * trans-intrinsic.c (gfc_conv_intrinsic_move_alloc): New function to
        handle the MOVE_ALLOC intrinsic with scalar and class arguments.
        * trans.c (trans_code): Call 'gfc_conv_intrinsic_move_alloc'.


2010-07-29  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/45004
        * gfortran.dg/move_alloc_2.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/move_alloc_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-stmt.h
    trunk/gcc/fortran/trans.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/45004] [OOP] Segfault with allocatable scalars and move_alloc
  2010-07-20 12:52 [Bug fortran/45004] New: [OOP] Segfault with allocatable scalars and move_alloc sfilippone at uniroma2 dot it
                   ` (4 preceding siblings ...)
  2010-07-29 18:15 ` janus at gcc dot gnu dot org
@ 2010-07-29 18:18 ` janus at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-07-29 18:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from janus at gcc dot gnu dot org  2010-07-29 18:18 -------
Fixed with r162688. Closing.


-- 

janus at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2010-07-29 18:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-20 12:52 [Bug fortran/45004] New: [OOP] Segfault with allocatable scalars and move_alloc sfilippone at uniroma2 dot it
2010-07-20 12:53 ` [Bug fortran/45004] " sfilippone at uniroma2 dot it
2010-07-22 21:22 ` janus at gcc dot gnu dot org
2010-07-22 21:45 ` janus at gcc dot gnu dot org
2010-07-23 16:20 ` janus at gcc dot gnu dot org
2010-07-29 18:15 ` janus at gcc dot gnu dot org
2010-07-29 18:18 ` janus at gcc dot gnu dot 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).