public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/100656 - ICE in gfc_conv_expr_present, at fortran/trans-expr.c:1934
@ 2021-05-26 21:04 Harald Anlauf
  2021-05-27  3:26 ` Jerry DeLisle
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-05-26 21:04 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear Fortranners,

Gerhard found a case where bounds-checking for an optional,
allocatable character dummy resulted in an ICE.  We'd better
not call the presence check on a non-dummy symbol, as this
will hit an assert...

Regtested on x86_64-pc-linux-gnu.

OK for mainline?  And backport to 11?

(The code in question has not been touched for nearly 10 years,
so I'm expecting this to be safe).

Thanks,
Harald


PR fortran/100656 - prevent ICE in gfc_conv_expr_present

gcc/fortran/ChangeLog:

	PR fortran/100656
	* trans-array.c (gfc_conv_ss_startstride): Do not call check for
	presence of a dummy argument when a symbol actually refers to a
	non-dummy.

gcc/testsuite/ChangeLog:

	PR fortran/100656
	* gfortran.dg/bounds_check_22.f90: New test.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr100656.patch --]
[-- Type: text/x-patch, Size: 1237 bytes --]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 6d38ea78273..7eeef554c0f 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -4718,8 +4718,9 @@ done:

 	  /* For optional arguments, only check bounds if the argument is
 	     present.  */
-	  if (expr->symtree->n.sym->attr.optional
-	      || expr->symtree->n.sym->attr.not_always_present)
+	  if ((expr->symtree->n.sym->attr.optional
+	       || expr->symtree->n.sym->attr.not_always_present)
+	      && expr->symtree->n.sym->attr.dummy)
 	    tmp = build3_v (COND_EXPR,
 			    gfc_conv_expr_present (expr->symtree->n.sym),
 			    tmp, build_empty_stmt (input_location));
diff --git a/gcc/testsuite/gfortran.dg/bounds_check_22.f90 b/gcc/testsuite/gfortran.dg/bounds_check_22.f90
new file mode 100644
index 00000000000..a84e3dd4f51
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/bounds_check_22.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! { dg-options "-fcheck=bounds" }
+! PR fortran/100656 - ICE in gfc_conv_expr_present
+
+subroutine s(x)
+  character(:), allocatable, optional :: x(:)
+  if ( present(x) ) then
+     if ( allocated(x) ) then
+        x = 'a' // x // 'e'
+     end if
+  end if
+end

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

* Re: [PATCH] PR fortran/100656 - ICE in gfc_conv_expr_present, at fortran/trans-expr.c:1934
  2021-05-26 21:04 [PATCH] PR fortran/100656 - ICE in gfc_conv_expr_present, at fortran/trans-expr.c:1934 Harald Anlauf
@ 2021-05-27  3:26 ` Jerry DeLisle
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2021-05-27  3:26 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

On 5/26/21 2:04 PM, Harald Anlauf via Fortran wrote:
> Dear Fortranners,
> 
> Gerhard found a case where bounds-checking for an optional,
> allocatable character dummy resulted in an ICE.  We'd better
> not call the presence check on a non-dummy symbol, as this
> will hit an assert...
> 
> Regtested on x86_64-pc-linux-gnu.
> 
> OK for mainline?  And backport to 11?
> 
> (The code in question has not been touched for nearly 10 years,
> so I'm expecting this to be safe).
> 
> Thanks,
> Harald
> 
> 
> PR fortran/100656 - prevent ICE in gfc_conv_expr_present
> 
> gcc/fortran/ChangeLog:
> 
> 	PR fortran/100656
> 	* trans-array.c (gfc_conv_ss_startstride): Do not call check for
> 	presence of a dummy argument when a symbol actually refers to a
> 	non-dummy.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR fortran/100656
> 	* gfortran.dg/bounds_check_22.f90: New test.
> 

Yes, OK on both.  Thanks

Jerry

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

end of thread, other threads:[~2021-05-27  3:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26 21:04 [PATCH] PR fortran/100656 - ICE in gfc_conv_expr_present, at fortran/trans-expr.c:1934 Harald Anlauf
2021-05-27  3:26 ` Jerry DeLisle

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).