public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
@ 2022-01-06 20:11 Sandra Loosemore
  2022-01-06 21:16 ` Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Sandra Loosemore @ 2022-01-06 20:11 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches

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

This patch fixes an ICE introduced with the recent-ish rewrite to inline 
the SIZE intrinsic, using a helper function to do the bulk of the work 
in producing the expansion.  It turns out to be a simple think-o type 
mistake in the wrapper around the helper rather than anything deeply 
wrong with the logic.

OK to check in?

-Sandra

[-- Attachment #2: pr103898.patch --]
[-- Type: text/x-patch, Size: 2215 bytes --]

commit 0e5b74440572f988dd96a6e9c33c11b59323d6cf
Author: Sandra Loosemore <sandra@codesourcery.com>
Date:   Thu Jan 6 11:23:18 2022 -0800

    Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
    
    This patch fixes a think-o in the code that triggered an ICE
    in the test case.
    
    2021-01-06  Sandra Loosemore  <sandra@codesourcery.com>
    
    	gcc/fortran/
    	* trans-intrinsic.c (gfc_conv_intrinsic_size): Make size_var
    	actually be a variable and fix surrounding code.
    
    	gcc/testsuite/
    	* gfortran.dg/pr103898.f90: New test.

diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 41252c9..aae34b0 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -8006,10 +8006,14 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr)
 	  cond = gfc_evaluate_now (cond, &se->pre);
 	  /* 'block2' contains the arg2 absent case, 'block' the arg2 present
 	      case; size_var can be used in both blocks. */
-	  tree size_var = gfc_tree_array_size (&block2, arg1, e, NULL_TREE);
+	  tree size_var = gfc_create_var (TREE_TYPE (size), "size");
 	  tmp = fold_build2_loc (input_location, MODIFY_EXPR,
 				 TREE_TYPE (size_var), size_var, size);
 	  gfc_add_expr_to_block (&block, tmp);
+	  size = gfc_tree_array_size (&block2, arg1, e, NULL_TREE);
+	  tmp = fold_build2_loc (input_location, MODIFY_EXPR,
+				 TREE_TYPE (size_var), size_var, size);
+	  gfc_add_expr_to_block (&block2, tmp);
 	  tmp = build3_v (COND_EXPR, cond, gfc_finish_block (&block),
 			  gfc_finish_block (&block2));
 	  gfc_add_expr_to_block (&se->pre, tmp);
diff --git a/gcc/testsuite/gfortran.dg/pr103898.f90 b/gcc/testsuite/gfortran.dg/pr103898.f90
new file mode 100644
index 0000000..6b4bb30
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103898.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+
+! This test used to ICE during gimplification (PR103898).
+
+Module g
+contains
+  function mysize(array, dim)
+    integer :: mysize
+    integer, dimension(:), intent(in)   :: array
+    integer, optional,     intent(in)   :: dim
+    if (present(dim)) then
+       mysize = size(array, dim=dim)
+    endif
+  end function mysize
+end module

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

* Re: [PATCH] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
  2022-01-06 20:11 [PATCH] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898] Sandra Loosemore
@ 2022-01-06 21:16 ` Harald Anlauf
  2022-01-06 21:16   ` Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2022-01-06 21:16 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches

Hi Sandra,

Am 06.01.22 um 21:11 schrieb Sandra Loosemore:
> This patch fixes an ICE introduced with the recent-ish rewrite to inline 
> the SIZE intrinsic, using a helper function to do the bulk of the work 
> in producing the expansion.  It turns out to be a simple think-o type 
> mistake in the wrapper around the helper rather than anything deeply 
> wrong with the logic.
> 
> OK to check in?

LGTM.

> -Sandra

Thanks for addressing this swiftly!


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

* Re: [PATCH] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
  2022-01-06 21:16 ` Harald Anlauf
@ 2022-01-06 21:16   ` Harald Anlauf
  0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2022-01-06 21:16 UTC (permalink / raw)
  To: Sandra Loosemore, fortran; +Cc: gcc-patches

Hi Sandra,

Am 06.01.22 um 21:11 schrieb Sandra Loosemore:
> This patch fixes an ICE introduced with the recent-ish rewrite to inline
> the SIZE intrinsic, using a helper function to do the bulk of the work
> in producing the expansion.  It turns out to be a simple think-o type
> mistake in the wrapper around the helper rather than anything deeply
> wrong with the logic.
>
> OK to check in?

LGTM.

> -Sandra

Thanks for addressing this swiftly!

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

end of thread, other threads:[~2022-01-06 21:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 20:11 [PATCH] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898] Sandra Loosemore
2022-01-06 21:16 ` Harald Anlauf
2022-01-06 21:16   ` Harald Anlauf

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