public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/51434 -- ICE in gfc_simplify_transfer
@ 2018-02-26 20:15 Steve Kargl
  2018-03-01 20:45 ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Kargl @ 2018-02-26 20:15 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]

All,

The attached patch fixes an ICE that occurs in gfc_simplify_tranfer.
The code that causes the problem is

  if (!gfc_is_constant_expr (source)
        || (gfc_init_expr_flag && !gfc_is_constant_expr (mold))
        || !gfc_is_constant_expr (size))
    return NULL;

in particular gfc_is_constant_expr (mold) leads to segfault.  Removing
the 2nd line allows the testcase to compile, but leads to several
regressions.  I went down the rabbit with gdb-8.0.1 to see why this
was dying a horrible death, and came away with a large headache.
After conferring with F95 and F2018, I concluded (and I coudl be
wrong) that mold simply needs to available as a scalar or an
array and it's actual value was not needed.  So, I decided to 
use gfc_reduce_expr (mold) to see if this would fix up some 
rogue pointer, and well it worked.  So, OK to commit?

2018-02-26  Steven G. Kargl  <kargl@gcc.gnu.org>

	PF fortran/51434
	* simplify.c (gfc_simplify_transfer): Reduce mold.

2018-02-26  Steven G. Kargl  <kargl@gcc.gnu.org>

	PF fortran/51434
	* gfortran.dg/pr51434.f90: New test.

-- 
Steve

[-- Attachment #2: pr51434.diff --]
[-- Type: text/x-diff, Size: 1679 bytes --]

Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 258006)
+++ gcc/fortran/simplify.c	(working copy)
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gfortran.h"
 #include "arith.h"
 #include "intrinsic.h"
+#include "match.h"
 #include "target-memory.h"
 #include "constructor.h"
 #include "version.h"	/* For version_string.  */
@@ -7370,10 +7371,12 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mol
   unsigned char *buffer;
   size_t result_length;
 
+  if (!gfc_is_constant_expr (source) || !gfc_is_constant_expr (size))
+    return NULL;
 
-  if (!gfc_is_constant_expr (source)
-	|| (gfc_init_expr_flag && !gfc_is_constant_expr (mold))
-	|| !gfc_is_constant_expr (size))
+  if (!gfc_resolve_expr (mold))
+    return NULL;
+  if (gfc_init_expr_flag && !gfc_is_constant_expr (mold))
     return NULL;
 
   if (!gfc_calculate_transfer_sizes (source, mold, size, &source_size,
Index: gcc/testsuite/gfortran.dg/pr51434.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr51434.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr51434.f90	(working copy)
@@ -0,0 +1,19 @@
+! { dg-do run }
+! PR fortran/51434
+module foo
+   implicit none
+   integer, parameter :: n = 5
+   character(len=1), parameter :: s(n) = 'a'
+   type :: a
+      integer :: m = n
+      character(len=1):: t(n) = transfer('abcde             ', s)
+   end type a
+end module foo
+
+program bar
+   use foo
+   implicit none
+   type(a) c
+   if (c%m /= n) stop 1
+   if (any(c%t /= ['a', 'b', 'c', 'd', 'e'])) stop 2
+end program bar

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR fortran/51434 -- ICE in gfc_simplify_transfer
  2018-02-26 20:15 [PATCH] PR fortran/51434 -- ICE in gfc_simplify_transfer Steve Kargl
@ 2018-03-01 20:45 ` Thomas Koenig
  2018-03-01 21:01   ` Steve Kargl
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2018-03-01 20:45 UTC (permalink / raw)
  To: sgk, fortran, gcc-patches

Hi Steve,

> 2018-02-26  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	PF fortran/51434
> 	* simplify.c (gfc_simplify_transfer): Reduce mold.


I think this should be "Resolve" (at least that is what your
patch shows).

OK for trunk, thanks for the patch!

Regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR fortran/51434 -- ICE in gfc_simplify_transfer
  2018-03-01 20:45 ` Thomas Koenig
@ 2018-03-01 21:01   ` Steve Kargl
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Kargl @ 2018-03-01 21:01 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: fortran, gcc-patches

On Thu, Mar 01, 2018 at 09:44:57PM +0100, Thomas Koenig wrote:
> Hi Steve,
> 
> > 2018-02-26  Steven G. Kargl  <kargl@gcc.gnu.org>
> > 
> > 	PF fortran/51434
> > 	* simplify.c (gfc_simplify_transfer): Reduce mold.
> 
> I think this should be "Resolve" (at least that is what your
> patch shows).
> 
> OK for trunk, thanks for the patch!
> 

Yes, I noticed that typo.  I tried gfc_reduce_expr and
gfc_simplify_expr, but both gave the ICE.  gfc_resolve_expr
works.

-- 
Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-01 21:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-26 20:15 [PATCH] PR fortran/51434 -- ICE in gfc_simplify_transfer Steve Kargl
2018-03-01 20:45 ` Thomas Koenig
2018-03-01 21:01   ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).