From 9995ce07f190d963ec52f52697ccc155dd079568 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Tue, 10 Dec 2019 10:32:12 +0000 Subject: [PATCH] =?utf8?q?Fortran]=20PR=2092872=20=E2=80=93=20Fix=20get=5F?= =?utf8?q?CFI=5Fdesc?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit PR fortran/92872 * trans-array.c (get_CFI_desc): Fix cond whether saved desc exists. PR fortran/92872 * gfortran.dg/bind_c_optional-1.f90: New. From-SVN: r279160 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/trans-array.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bbc00ae..86a1a14 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2019-12-10 Tobias Burnus + + PR fortran/92872 + * trans-array.c (get_CFI_desc): Fix cond whether saved desc exists. + 2019-12-09 David Malcolm * error.c (gfc_diagnostic_starter): Add pp_newline call before diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 5c27c06..1b77998 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -882,7 +882,7 @@ get_CFI_desc (gfc_symbol *sym, gfc_expr *expr, else tmp = sym->backend_decl; - if (tmp && DECL_LANG_SPECIFIC (tmp)) + if (tmp && DECL_LANG_SPECIFIC (tmp) && GFC_DECL_SAVED_DESCRIPTOR (tmp)) tmp = GFC_DECL_SAVED_DESCRIPTOR (tmp); *desc = tmp; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7ba847d..b43497c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-10 Tobias Burnus + + PR fortran/92872 + * gfortran.dg/bind_c_optional-1.f90: New. + 2019-12-10 Richard Sandiford * gcc.dg/lto/tag-1_0.c, gcc.dg/lto/tag-1_1.c: New test. diff --git a/gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 b/gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 new file mode 100644 index 0000000..9940920 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind_c_optional-1.f90 @@ -0,0 +1,22 @@ +! { dg-do run } +! +! PR fortran/92872 +! +! Contributed by G. Steinmetz +! +module m +contains +subroutine s(x) bind(c) + integer, allocatable, optional :: x(:) + x = [1, 2, 3] +end +end + +use m +integer, allocatable :: y(:) +! NOTE: starting at 0, otherwise it will fail due to PR 92189 +allocate(y(0:2)) +y = [9, 8, 7] +call s(y) +if (any (y /= [1, 2, 3])) stop 1 +end -- 2.7.4