]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR fortran/100656 - prevent ICE in gfc_conv_expr_present
authorHarald Anlauf <anlauf@gmx.de>
Thu, 27 May 2021 11:55:11 +0000 (13:55 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Thu, 27 May 2021 11:55:11 +0000 (13:55 +0200)
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.

gcc/fortran/trans-array.c
gcc/testsuite/gfortran.dg/bounds_check_22.f90 [new file with mode: 0644]

index 6d38ea78273c593c6f76c0e226f87838cbefc4a0..7eeef554c0f1d68873e6486c8aeac89603effee2 100644 (file)
@@ -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 (file)
index 0000000..a84e3dd
--- /dev/null
@@ -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