* [PATCH] PR fortran/92019 -- BOZ cannot be an array index
@ 2019-10-09 20:26 Steve Kargl
2019-10-11 14:53 ` Janne Blomqvist
0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2019-10-09 20:26 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 372 bytes --]
The attach patch fixes an ICE caused by the use of a bOZ as
an array index. Tested on x86_64-*-freebsd. OK to commit?
2019-10-09 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/92019
* array.c (match_subscript): BOZ cannot be an array subscript.
2019-10-09 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/92019
* gfortran.dg/pr92019.f90: New test.
--
Steve
[-- Attachment #2: pr92019.diff --]
[-- Type: text/x-diff, Size: 2298 bytes --]
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c (revision 276705)
+++ gcc/fortran/array.c (working copy)
@@ -66,6 +66,7 @@ match_subscript (gfc_array_ref *ar, int init, bool mat
match m = MATCH_ERROR;
bool star = false;
int i;
+ bool saw_boz = false;
i = ar->dimen + ar->codimen;
@@ -91,6 +92,12 @@ match_subscript (gfc_array_ref *ar, int init, bool mat
else if (!star)
m = gfc_match_expr (&ar->start[i]);
+ if (ar->start[i] && ar->start[i]->ts.type == BT_BOZ)
+ {
+ gfc_error ("Invalid BOZ literal constant used in subscript at %C");
+ saw_boz = true;
+ }
+
if (m == MATCH_NO)
gfc_error ("Expected array subscript at %C");
if (m != MATCH_YES)
@@ -117,6 +124,12 @@ end_element:
else
m = gfc_match_expr (&ar->end[i]);
+ if (ar->end[i] && ar->end[i]->ts.type == BT_BOZ)
+ {
+ gfc_error ("Invalid BOZ literal constant used in subscript at %C");
+ saw_boz = true;
+ }
+
if (m == MATCH_ERROR)
return MATCH_ERROR;
@@ -132,6 +145,12 @@ end_element:
m = init ? gfc_match_init_expr (&ar->stride[i])
: gfc_match_expr (&ar->stride[i]);
+ if (ar->stride[i] && ar->stride[i]->ts.type == BT_BOZ)
+ {
+ gfc_error ("Invalid BOZ literal constant used in subscript at %C");
+ saw_boz = true;
+ }
+
if (m == MATCH_NO)
gfc_error ("Expected array subscript stride at %C");
if (m != MATCH_YES)
@@ -142,7 +161,7 @@ matched:
if (star)
ar->dimen_type[i] = DIMEN_STAR;
- return MATCH_YES;
+ return (saw_boz ? MATCH_ERROR : MATCH_YES);
}
Index: gcc/testsuite/gfortran.dg/pr92019.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr92019.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr92019.f90 (working copy)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/92019
+program foo
+ integer :: a(4) = [1, 2, 3, 4]
+ print *, a(z'1') ! { dg-error "Invalid BOZ literal constant" }
+ print *, a(1:z'3') ! { dg-error "Invalid BOZ literal constant" }
+ print *, a(1:2:z'2') ! { dg-error "Invalid BOZ literal constant" }
+ print *, a([z'2',z'1']) ! { dg-error "cannot appear in an array constructor" }
+end program foo
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PR fortran/92019 -- BOZ cannot be an array index
2019-10-09 20:26 [PATCH] PR fortran/92019 -- BOZ cannot be an array index Steve Kargl
@ 2019-10-11 14:53 ` Janne Blomqvist
0 siblings, 0 replies; 2+ messages in thread
From: Janne Blomqvist @ 2019-10-11 14:53 UTC (permalink / raw)
To: Steve Kargl; +Cc: Fortran List, GCC Patches
On Wed, Oct 9, 2019 at 11:26 PM Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
>
> The attach patch fixes an ICE caused by the use of a bOZ as
> an array index. Tested on x86_64-*-freebsd. OK to commit?
>
> 2019-10-09 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/92019
> * array.c (match_subscript): BOZ cannot be an array subscript.
>
> 2019-10-09 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/92019
> * gfortran.dg/pr92019.f90: New test.
>
> --
> Steve
Ok.
--
Janne Blomqvist
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-11 14:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 20:26 [PATCH] PR fortran/92019 -- BOZ cannot be an array index Steve Kargl
2019-10-11 14:53 ` Janne Blomqvist
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).