]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix testcases that violate C838, + revealed ICE
authorSandra Loosemore <sandra@codesourcery.com>
Thu, 23 Sep 2021 00:24:58 +0000 (17:24 -0700)
committerSandra Loosemore <sandra@codesourcery.com>
Thu, 23 Sep 2021 00:24:58 +0000 (17:24 -0700)
The three test cases fixed in this patch violated F2018 C838, which
only allows passing an assumed-rank argument to an assumed-rank dummy.
Wrapping the call in "select rank" revealed a null pointer dereference
which is fixed by guarding the use of the result of
GFC_DECL_SAVED_DESCRIPTOR similar to what is already done elsewhere.

2021-09-19  Sandra Loosemore  <sandra@codesourcery.com>

gcc/fortran/
* trans-stmt.c (trans_associate_var): Check that result of
GFC_DECL_SAVED_DESCRIPTOR is not null before using it.

gcc/testsuite/
* gfortran.dg/assumed_rank_18.f90 (g): Wrap call to h in
select rank.
* gfortran.dg/assumed_type_10.f90 (test_array): Likewise for
call to test_lib.
* gfortran.dg/assumed_type_11.f90 (test_array): Likewise.

(cherry picked from commit 8fa9e73e6db0ff05447f5547df925fdcb4733d05)

gcc/fortran/ChangeLog.omp
gcc/fortran/trans-stmt.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/assumed_rank_18.f90
gcc/testsuite/gfortran.dg/assumed_type_10.f90
gcc/testsuite/gfortran.dg/assumed_type_11.f90

index 1a49de61a8d70fcf9bca5007307b822693043484..cf3b5efc0ce541d6f00fb460e2a7e934c9651e15 100644 (file)
@@ -1,3 +1,11 @@
+2021-09-22  Sandra Loosemore  <sandra@codesourcery.com>
+
+       Backported from master:
+       2021-09-19  Sandra Loosemore  <sandra@codesourcery.com>
+
+       * trans-stmt.c (trans_associate_var): Check that result of
+       GFC_DECL_SAVED_DESCRIPTOR is not null before using it.
+
 2021-09-22  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index 193cc9090d61484a3582d949a7ebceb43fc71953..3a68a159a922fb31288546ca934c81e348721711 100644 (file)
@@ -1788,9 +1788,10 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block)
          /* Go straight to the class data.  */
          if (sym2->attr.dummy && !sym2->attr.optional)
            {
-             class_decl = DECL_LANG_SPECIFIC (sym2->backend_decl) ?
-                          GFC_DECL_SAVED_DESCRIPTOR (sym2->backend_decl) :
-                          sym2->backend_decl;
+             class_decl = sym2->backend_decl;
+             if (DECL_LANG_SPECIFIC (class_decl)
+                 && GFC_DECL_SAVED_DESCRIPTOR (class_decl))
+               class_decl = GFC_DECL_SAVED_DESCRIPTOR (class_decl);
              if (POINTER_TYPE_P (TREE_TYPE (class_decl)))
                class_decl = build_fold_indirect_ref_loc (input_location,
                                                          class_decl);
index 16a511512ec2ec898efb73b88645a04d28165ce0..434b064c6107eaf89d0bf00bb42af005078702bf 100644 (file)
@@ -1,3 +1,14 @@
+2021-09-22  Sandra Loosemore  <sandra@codesourcery.com>
+
+       Backported from master:
+       2021-09-19  Sandra Loosemore  <sandra@codesourcery.com>
+
+       * gfortran.dg/assumed_rank_18.f90 (g): Wrap call to h in
+       select rank.
+       * gfortran.dg/assumed_type_10.f90 (test_array): Likewise for
+       call to test_lib.
+       * gfortran.dg/assumed_type_11.f90 (test_array): Likewise.
+
 2021-09-22  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index a8fa3ff78d917e993a6a20035ff65eda337ea9f4..0bc419ac6d7e601400db3e8c8ee5fb5625ee4ed8 100644 (file)
@@ -7,7 +7,10 @@ program p
 contains
    subroutine g(x)
       real :: x(..)
-      call h(x)
+      select rank (x)
+        rank (1)
+          call h(x)
+      end select
    end
    subroutine h(x)
       real :: x(*)
index bf0c87320ca3dfa9b180cf684c671dfeaa1ca5e3..a8bbf2d343ea0fe3cbf4e206428b5a69b53309a1 100644 (file)
@@ -31,7 +31,10 @@ contains
   subroutine test_array (a)
     use iso_c_binding, only: c_size_t
     class(*), dimension(..), target :: a
-    call test_lib (a, int (sizeof (a), kind=c_size_t))
+    select rank (a)
+      rank (1)
+        call test_lib (a, int (sizeof (a), kind=c_size_t))
+    end select
   end subroutine
 
 end module
index df6572dd5b39082d98447ca0d91e8bc25aeef12f..391fa0de8f22284cba80a5d4e6467a9d16058e1a 100644 (file)
@@ -31,7 +31,10 @@ contains
   subroutine test_array (a)
     use iso_c_binding, only: c_size_t
     class(*), dimension(..), target :: a
-    call test_lib (a, int (sizeof (a), kind=c_size_t))
+    select rank (a)
+      rank (1)
+        call test_lib (a, int (sizeof (a), kind=c_size_t))
+    end select
   end subroutine
 
 end module