This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/58469] New: Defined assignment: ICE, possible wrong value


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

            Bug ID: 58469
           Summary: Defined assignment: ICE,  possible wrong value
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org

The following code segfaults, unless the patch below is applied. With the patch
applied, valgrind shows that the gfc_code allocated at
  if ((*code)->expr1->symtree->n.sym->name[2] != '@')
    {
      this_code = build_assignment (EXEC_ASSIGN,
leaks memory. (I have no idea why.)


Additionally, I wonder what the code should print - 20 or 42. With the current
code (plus patch) and with crayftn it prints 20. (ifort and pgf95 segfault.) I
have the vague feeling that 42 is correct, but I am far from being positive.



module m0
  implicit none
  type :: component
    integer :: i = 42
  contains
    procedure :: assign0
    generic :: assignment(=) => assign0
  end type
  type, extends(component) :: comp2
    real :: aa
  end type comp2
  type parent
    type(comp2) :: foo
  end type
contains
  elemental subroutine assign0(lhs,rhs)
    class(component), intent(INout) :: lhs
    class(component), intent(in) :: rhs
    lhs%i = 20
  end subroutine
end module

program main
  use m0
  implicit none
  type(parent), allocatable :: left
  type(parent) :: right
  print *, right%foo
  left = right
  print *, left%foo
!  if (left%foo%i /= 42) call abort()
end


Patch which does three things:
a) Correct indenting
b) Remove pointless code. "this_code" is either freed or (via
add_code_to_chain) nullified.
c) Fix for the segfault.

--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -9623,3 +9623,3 @@ generate_component_assignments (gfc_code **code,
         }
-      }
+    }
       else if (this_code->op == EXEC_ASSIGN && !this_code->next)
@@ -9645,9 +9645,2 @@ generate_component_assignments (gfc_code **code,

-  /* This is probably not necessary.  */
-  if (this_code)
-    {
-      gfc_free_statements (this_code);
-      this_code = NULL;
-    }
-
   /* Put the temporary assignments at the top of the generated code.  */
@@ -9669,3 +9662,4 @@ generate_component_assignments (gfc_code **code,
   **code = *head;
-  free (head);
+  if (head != tail)
+    free (head);
   *code = tail;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]