From b036979093e912243a4ff999a50feb86fe6f7889 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Wed, 8 Nov 2017 22:56:58 +0000 Subject: [PATCH] re PR fortran/82841 (Segfault in gfc_simplify_transfer) 2017-11-08 Steven G. Kargl PR Fortran/82841 * simplify.c(gfc_simplify_transfer): Do not dereference a NULL pointer. Unwrap a short line. 2017-11-08 Steven G. Kargl PR Fortran/82841 * gfortran.dg/transfer_simplify_11.f90: new test. From-SVN: r254555 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/simplify.c | 5 ++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/transfer_simplify_11.f90 | 8 ++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/transfer_simplify_11.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b554f9f7937..6c9f246d64e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-11-08 Steven G. Kargl + + PR Fortran/82841 + * simplify.c(gfc_simplify_transfer): Do not dereference a NULL pointer. + Unwrap a short line. + 2017-11-08 Steven G. Kargl PR fortran/82884 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index ba010a0aebf..c7b7e1a8297 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -6576,8 +6576,7 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size) return NULL; /* Calculate the size of the source. */ - if (source->expr_type == EXPR_ARRAY - && !gfc_array_size (source, &tmp)) + if (source->expr_type == EXPR_ARRAY && !gfc_array_size (source, &tmp)) gfc_internal_error ("Failure getting length of a constant array."); /* Create an empty new expression with the appropriate characteristics. */ @@ -6585,7 +6584,7 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size) &source->where); result->ts = mold->ts; - mold_element = mold->expr_type == EXPR_ARRAY + mold_element = (mold->expr_type == EXPR_ARRAY && mold->value.constructor) ? gfc_constructor_first (mold->value.constructor)->expr : mold; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 475cc27b3c8..75c8a0ab752 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-08 Steven G. Kargl + + PR Fortran/82841 + * gfortran.dg/transfer_simplify_11.f90: New test. + 2017-11-08 Steven G. Kargl PR fortran/82884 diff --git a/gcc/testsuite/gfortran.dg/transfer_simplify_11.f90 b/gcc/testsuite/gfortran.dg/transfer_simplify_11.f90 new file mode 100644 index 00000000000..ce7a4ad5e56 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/transfer_simplify_11.f90 @@ -0,0 +1,8 @@ +! { dg-do run } +! PR Fortran/82841 +! + integer, parameter :: N = 2 + character(len=1) :: chr(N) + chr = transfer(repeat("x",ncopies=N),[character(len=1) ::], N) + if (chr(1) /= 'x' .and. chr(2) /= 'x') call abort +end -- 2.30.2