[Bug fortran/66089] [7/8/9 Regression] elemental dependency mishandling when derived types are involved

tkoenig at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Feb 5 20:14:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66089

--- Comment #28 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
This patch

Index: dependency.c                                                             
===================================================================             
--- dependency.c        (Revision 268432)                                       
+++ dependency.c        (Arbeitskopie)                                          
@@ -2100,10 +2100,26 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gf      

   while (lref && rref)                                                         
     {                                                                          
+      /* Skip any class components, we could be comparing a class and          
+        a corresponding type.  */                                              
+                                                                               
+      if (lref->type == REF_COMPONENT && CLASS_DATA (lref->u.c.component))     
+       {                                                                       
+         lref = lref->next;                                                    
+         continue;                                                             
+       }                                                                       
+                                                                               
+      if (rref->type == REF_COMPONENT && CLASS_DATA (rref->u.c.component))
+       {
+         rref = rref->next;
+         continue;
+       }
+
       /* We're resolving from the same base symbol, so both refs should be
         the same type.  We traverse the reference chain until we find ranges
         that are not equal.  */
       gcc_assert (lref->type == rref->type);
+
       switch (lref->type)
        {
        case REF_COMPONENT:

gets past the ICE, but now there is a wrong code, the
dependency is not handled correctly:

ig25@linux-p51k:~/Krempel/66089> cat a.f90
  type :: t
    integer :: c
  end type t

  type(t),  dimension(5) :: a, b
  class(t), dimension(:), allocatable :: c

  a = t(1)
  b = t(7)
  allocate(c(5), source=t(13))
  c = plus(c(1), b)
  print *, c%c
  if (any(c%c /= 20)) call abort

contains

  elemental function plus(lhs, rhs)
    class(t), intent(in) :: lhs, rhs                                            
    type(t)             :: plus                                                 
    plus%c = lhs%c + rhs%c                                                      
  end function plus                                                             

end                                                                             
ig25@linux-p51k:~/Krempel/66089> gfortran a.f90 && ./a.out                      
          20          27          27          27          27                    

Program aborted. Backtrace:                                                     
#0  0x400dd6 in ???                                                             
#1  0x400e49 in ???                                                             
#2  0x7fbc0563d724 in ???                                                       
#3  0x400858 in ???                                                             
        at ../sysdeps/x86_64/start.S:118                                        
#4  0xffffffffffffffff in ???                                                   
Abgebrochen (Speicherabzug geschrieben)


More information about the Gcc-bugs mailing list