re PR fortran/81447 ([7/8] gfortran fails to recognize the exact dynamic type of...
authorPaul Thomas <pault@gcc.gnu.org>
Sun, 5 Nov 2017 12:38:42 +0000 (12:38 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sun, 5 Nov 2017 12:38:42 +0000 (12:38 +0000)
2017-11-05  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/81447
PR fortran/82783
* resolve.c (resolve_component): There is no need to resolve
the components of a use associated vtype.
(resolve_fl_derived): Unconditionally generate a vtable for any
module derived type, as long as the standard is F2003 or later
and it is not a vtype or a PDT template.

2017-11-05  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/81447
* gfortran.dg/class_65.f90: New test.
* gfortran.dg/alloc_comp_basics_1.f90: Increase builtin_free
count from 18 to 21.
* gfortran.dg/allocatable_scalar_9.f90: Increase builtin_free
count from 32 to 54.
* gfortran.dg/auto_dealloc_1.f90: Increase builtin_free
count from 4 to 10.
* gfortran.dg/coarray_lib_realloc_1.f90: Increase builtin_free
count from 3 to 6. Likewise _gfortran_caf_deregister from 2 to
3, builtin_malloc from 1 to 4 and builtin_memcpy|= MEM from
2 to 5.
* gfortran.dg/finalize_28.f90: Increase builtin_free
count from 3 to 6.
* gfortran.dg/move_alloc_15.f90: Increase builtin_free and
builtin_malloc counts from 11 to 14.
* gfortran.dg/typebound_proc_27.f03: Increase builtin_free
count from 7 to 10. Likewise builtin_malloc from 12 to 15.

From-SVN: r254427

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/alloc_comp_basics_1.f90
gcc/testsuite/gfortran.dg/allocatable_scalar_9.f90
gcc/testsuite/gfortran.dg/auto_dealloc_1.f90
gcc/testsuite/gfortran.dg/class_65.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/coarray_lib_realloc_1.f90
gcc/testsuite/gfortran.dg/finalize_28.f90
gcc/testsuite/gfortran.dg/move_alloc_15.f90
gcc/testsuite/gfortran.dg/typebound_proc_27.f03

index 008d86fe060801d3160c997ec09e992b3a761de3..1a4da461e1c4227a540a741275cb5a3626c9faac 100644 (file)
@@ -1,3 +1,13 @@
+2017-11-05  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/81447
+       PR fortran/82783
+       * resolve.c (resolve_component): There is no need to resolve
+       the components of a use associated vtype.
+       (resolve_fl_derived): Unconditionally generate a vtable for any
+       module derived type, as long as the standard is F2003 or later
+       and it is not a vtype or a PDT template.
+
 2017-11-05  Tom de Vries  <tom@codesourcery.com>
 
        PR other/82784
index 40c1cd3c96fb2828cb5d751c0837a758180d637f..50b4b49fe97476961a0abb7932b2f3bcfb3a4be1 100644 (file)
@@ -13496,6 +13496,9 @@ resolve_component (gfc_component *c, gfc_symbol *sym)
   if (c->attr.artificial)
     return true;
 
+  if (sym->attr.vtype && sym->attr.use_assoc)
+    return true;
+
   /* F2008, C442.  */
   if ((!sym->attr.is_class || c != sym->components)
       && c->attr.codimension
@@ -14075,6 +14078,20 @@ resolve_fl_derived (gfc_symbol *sym)
   if (!resolve_typebound_procedures (sym))
     return false;
 
+  /* Generate module vtables subject to their accessibility and their not
+     being vtables or pdt templates. If this is not done class declarations
+     in external procedures wind up with their own version and so SELECT TYPE
+     fails because the vptrs do not have the same address.  */
+  if (gfc_option.allow_std & GFC_STD_F2003
+      && sym->ns->proc_name
+      && sym->ns->proc_name->attr.flavor == FL_MODULE
+      && sym->attr.access != ACCESS_PRIVATE
+      && !(sym->attr.use_assoc || sym->attr.vtype || sym->attr.pdt_template))
+    {
+      gfc_symbol *vtab = gfc_find_derived_vtab (sym);
+      gfc_set_sym_referenced (vtab);
+    }
+
   return true;
 }
 
@@ -15943,7 +15960,7 @@ resolve_equivalence (gfc_equiv *eq)
            {
              gfc_use_rename *r;
              for (r = sym->ns->use_stmts->rename; r; r = r->next)
-               if (strcmp(r->use_name, sym->name) == 0) saw_sym = true; 
+               if (strcmp(r->use_name, sym->name) == 0) saw_sym = true;
            }
          else
            saw_sym = true;
index e4ab15974e06b24b077d7366cd800efd9e7e7ee6..993dca9fee7caac9240e9d8cb1eb92345e537792 100644 (file)
@@ -1,3 +1,24 @@
+2017-11-05  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/81447
+       * gfortran.dg/class_65.f90: New test.
+       * gfortran.dg/alloc_comp_basics_1.f90: Increase builtin_free
+       count from 18 to 21.
+       * gfortran.dg/allocatable_scalar_9.f90: Increase builtin_free
+       count from 32 to 54.
+       * gfortran.dg/auto_dealloc_1.f90: Increase builtin_free
+       count from 4 to 10.
+       * gfortran.dg/coarray_lib_realloc_1.f90: Increase builtin_free
+       count from 3 to 6. Likewise _gfortran_caf_deregister from 2 to
+       3, builtin_malloc from 1 to 4 and builtin_memcpy|= MEM from
+       2 to 5.
+       * gfortran.dg/finalize_28.f90: Increase builtin_free
+       count from 3 to 6.
+       * gfortran.dg/move_alloc_15.f90: Increase builtin_free and
+       builtin_malloc counts from 11 to 14.
+       * gfortran.dg/typebound_proc_27.f03: Increase builtin_free
+       count from 7 to 10. Likewise builtin_malloc from 12 to 15.
+
 2017-11-04  Daniel Santos  <daniel.santos@pobox.com>
 
        gcc.target/i386/pr82002-2a.c: Change from xfail to fail.
index 0b5ef274cc4c16b15492a444d4cb1bec1ee8ad41..44d1c8bc0e69eca01a7a0adf05f27105ef67d5d2 100644 (file)
@@ -141,4 +141,4 @@ contains
     end subroutine check_alloc2
 
 end program alloc
-! { dg-final { scan-tree-dump-times "builtin_free" 18 "original" } }
+! { dg-final { scan-tree-dump-times "builtin_free" 21 "original" } }
index d36175cd8d3e97fbc4d855344832e953001e04ff..802c5f7bc8d095e04589488b7a146e3eb06d4a1e 100644 (file)
@@ -5,13 +5,13 @@
 !
 ! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
 
-module m                                                                        
-type st                                                                         
-  integer , allocatable :: a1                                                   
-end type st                                                                     
-type at                                                                         
-  integer , allocatable :: a2(:)                                                
-end type at                                                                     
+module m
+type st
+  integer , allocatable :: a1
+end type st
+type at
+  integer , allocatable :: a2(:)
+end type at
 
 type t1
   type(st), allocatable :: b1
@@ -52,4 +52,4 @@ if(allocated(na4%b4)) call abort()
 end block
 end
 
-! { dg-final { scan-tree-dump-times "__builtin_free" 32 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_free" 54 "original" } }
index 4f15bcd6159214ccb89564383f5cb5c943f88fac..99ecd1df85639c2b94334833360c124a2f7aff3c 100644 (file)
@@ -50,7 +50,7 @@ contains
     m%k%i = 45
   end subroutine
 
-end module 
+end module
 
 
-! { dg-final { scan-tree-dump-times "__builtin_free" 4 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_free" 10 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/class_65.f90 b/gcc/testsuite/gfortran.dg/class_65.f90
new file mode 100644 (file)
index 0000000..a82918c
--- /dev/null
@@ -0,0 +1,41 @@
+! { dg-do run }
+!
+! Test the fix for PR81447 in which a vtable was not being created
+! in the module 'm' so that x->vptr in 's' did not have the same
+! value as that in 'p'.
+!
+! Contributed by Mat Cross  <mathewc@nag.co.uk>
+!
+Module m
+  Type :: t
+    integer :: i
+  End Type
+End Module
+
+Program p
+  Use m
+  Class (t), Allocatable :: x
+  Interface
+    Subroutine s(x)
+      Use m
+      Class (t), Allocatable :: x
+    End Subroutine
+  End Interface
+  Call s(x)
+  Select Type (x)
+  Type Is (t)
+    Continue
+  Class Is (t)
+    call abort
+  Class Default
+    call abort
+  End Select
+!  Print *, 'ok'
+End Program
+
+Subroutine s(x)
+  Use m, Only: t
+  Implicit None
+  Class (t), Allocatable :: x
+  Allocate (t :: x)
+End Subroutine
index c55507b582122cb9916f0c61e41d199b451d6c66..559d880b5ac46a3679aab88c2448117dc535f07d 100644 (file)
@@ -21,14 +21,14 @@ x = y
 end
 
 ! For comp%ii: End of scope of x + y (2x) and for the LHS of the assignment (1x)
-! { dg-final { scan-tree-dump-times "__builtin_free" 3 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_free" 6 "original" } }
 
 ! For comp%CAF:  End of scope of x + y (2x); no LHS freeing for the CAF in assignment
-! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister" 2 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_deregister" 3 "original" } }
 
 ! Only malloc "ii":
-! { dg-final { scan-tree-dump-times "__builtin_malloc" 1 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_malloc" 4 "original" } }
 
 ! But copy "ii" and "CAF":
-! { dg-final { scan-tree-dump-times "__builtin_memcpy|= MEM" 2 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_memcpy|= MEM" 5 "original" } }
 
index 03de5d0d28bc442f424257b7553e68d4bcf32589..f0c9665252f46a455fe8877b0dae51f9af381e02 100644 (file)
@@ -21,4 +21,4 @@ contains
     integer, intent(out) :: edges(:,:)
   end subroutine coo_dump_edges
 end module coo_graphs
-! { dg-final { scan-tree-dump-times "__builtin_free" 3 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_free" 6 "original" } }
index 1c96ccba1cf4e8d8b7a64194229e42ac20929f3b..0c8cacf3cf0625d39bf699337bd89bce59829133 100644 (file)
@@ -84,5 +84,5 @@ contains
     end do
   end subroutine
 end program name
-! { dg-final { scan-tree-dump-times "__builtin_malloc" 11 "original" } }
-! { dg-final { scan-tree-dump-times "__builtin_free" 11 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_malloc" 14 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_free" 14 "original" } }
index 29332c4169cd0b824e96a0759e526c8bca556ece..06484942277d372ed50b87a9272524e0e7796a2a 100644 (file)
@@ -1,6 +1,6 @@
 ! { dg-do run }
 ! { dg-options "-fdump-tree-original" }
-! 
+!
 ! PR fortran/47586
 ! Missing deep copy for data pointer returning functions when the type
 ! has allocatable components
@@ -77,15 +77,15 @@ end program prog
 ! statements.
 ! It is assumed that if the number of allocate is right, the number of
 ! deep copies is right too.
-! { dg-final { scan-tree-dump-times "__builtin_malloc" 12 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_malloc" 15 "original" } }
 
 !
 ! Realloc are only used for assignments to `that%i'.  Don't know why.
 ! { dg-final { scan-tree-dump-times "__builtin_realloc" 6 "original" } }
-! 
+!
 
 ! No leak: Only assignments to `this' use malloc.  Assignments to `that%i'
 ! take the realloc path after the first assignment, so don't count as a malloc.
-! { dg-final { scan-tree-dump-times "__builtin_free" 7 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_free" 10 "original" } }
 !