summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkargl <kargl@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-10 18:47:44 +0000
committerkargl <kargl@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-10 18:47:44 +0000
commite07b30081bcb9fcdaad021f271f67022ff7388a1 (patch)
tree2240ff233042f23a9416172e0fe9662576689259
parent520bf3a62d2c36cf41876b250c412efb05952fde (diff)
downloadgcc-e07b30081bcb9fcdaad021f271f67022ff7388a1.tar.gz
2018-01-10 Steven G. Kargl <kargl@kgcc.gnu.org>
Backport r254555 from trunk PR Fortran/82841 * gfortran.dg/transfer_simplify_11.f90: New test. 2018-01-10 Steven G. Kargl <kargl@kgcc.gnu.org> Backport r254555 from trunk PR Fortran/82841 * simplify.c(gfc_simplify_transfer): Do not dereference a NULL pointer. Unwrap a short line. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@256445 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/simplify.c5
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gfortran.dg/transfer_simplify_11.f908
4 files changed, 23 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index fc48b8b70d7..ff6d4e86933 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2018-01-10 Steven G. Kargl <kargl@kgcc.gnu.org>
+
+ Backport r254555 from trunk
+ PR Fortran/82841
+ * simplify.c(gfc_simplify_transfer): Do not dereference a NULL pointer.
+ Unwrap a short line.
+
2018-01-04 Steven G. Kargl <kargl@gcc.gnu.org>
PR Fortran/83679
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 5a6ef8fb029..a9d8c7534b8 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6577,8 +6577,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. */
@@ -6586,7 +6585,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 83a27ab66f1..5816836e846 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-10 Steven G. Kargl <kargl@kgcc.gnu.org>
+
+ Backport r254555 from trunk
+ PR Fortran/82841
+ * gfortran.dg/transfer_simplify_11.f90: New test.
+
2018-01-09 Richard Biener <rguenther@suse.de>
Backport from mainline
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