[gcc/devel/omp/gcc-11] Fortran: Fix testcases that violate C838, + revealed ICE
Sandra Loosemore
sandra@gcc.gnu.org
Thu Sep 23 02:34:04 GMT 2021
https://gcc.gnu.org/g:e05c54b1d4e113b06f1208b99f999279310e78f8
commit e05c54b1d4e113b06f1208b99f999279310e78f8
Author: Sandra Loosemore <sandra@codesourcery.com>
Date: Wed Sep 22 17:24:58 2021 -0700
Fortran: Fix testcases that violate C838, + revealed ICE
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)
Diff:
---
gcc/fortran/ChangeLog.omp | 8 ++++++++
gcc/fortran/trans-stmt.c | 7 ++++---
gcc/testsuite/ChangeLog.omp | 11 +++++++++++
gcc/testsuite/gfortran.dg/assumed_rank_18.f90 | 5 ++++-
gcc/testsuite/gfortran.dg/assumed_type_10.f90 | 5 ++++-
gcc/testsuite/gfortran.dg/assumed_type_11.f90 | 5 ++++-
6 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 1a49de61a8d..cf3b5efc0ce 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -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:
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 193cc9090d6..3a68a159a92 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -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);
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 16a511512ec..434b064c610 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -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:
diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_18.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_18.f90
index a8fa3ff78d9..0bc419ac6d7 100644
--- a/gcc/testsuite/gfortran.dg/assumed_rank_18.f90
+++ b/gcc/testsuite/gfortran.dg/assumed_rank_18.f90
@@ -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(*)
diff --git a/gcc/testsuite/gfortran.dg/assumed_type_10.f90 b/gcc/testsuite/gfortran.dg/assumed_type_10.f90
index bf0c87320ca..a8bbf2d343e 100644
--- a/gcc/testsuite/gfortran.dg/assumed_type_10.f90
+++ b/gcc/testsuite/gfortran.dg/assumed_type_10.f90
@@ -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
diff --git a/gcc/testsuite/gfortran.dg/assumed_type_11.f90 b/gcc/testsuite/gfortran.dg/assumed_type_11.f90
index df6572dd5b3..391fa0de8f2 100644
--- a/gcc/testsuite/gfortran.dg/assumed_type_11.f90
+++ b/gcc/testsuite/gfortran.dg/assumed_type_11.f90
@@ -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
More information about the Gcc-cvs
mailing list