* [PATCH] PR fortran/102716 - ICE in gfc_validate_kind(): Got bad kind
@ 2021-10-13 19:36 Harald Anlauf
2021-10-14 6:00 ` Thomas Koenig
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-10-13 19:36 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 306 bytes --]
Dear Fortranners,
another simple and obvious fix: we need to reorder the argument checks
to the SHAPE intrinsic so that invalid KIND arguments can be detected.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
As I consider this a safe fix, I'd like to backport to suitable branches.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr102716.diff --]
[-- Type: text/x-patch, Size: 1647 bytes --]
Fortran: fix order of checks for the SHAPE intrinsic
gcc/fortran/ChangeLog:
PR fortran/102716
* check.c (gfc_check_shape): Reorder checks so that invalid KIND
arguments can be detected.
gcc/testsuite/ChangeLog:
PR fortran/102716
* gfortran.dg/shape_10.f90: New test.
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 677209ee95e..cfaf9d26bbc 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5086,6 +5086,13 @@ gfc_check_shape (gfc_expr *source, gfc_expr *kind)
if (gfc_invalid_null_arg (source))
return false;
+ if (!kind_check (kind, 1, BT_INTEGER))
+ return false;
+ if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
+ "with KIND argument at %L",
+ gfc_current_intrinsic, &kind->where))
+ return false;
+
if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
return true;
@@ -5098,13 +5105,6 @@ gfc_check_shape (gfc_expr *source, gfc_expr *kind)
return false;
}
- if (!kind_check (kind, 1, BT_INTEGER))
- return false;
- if (kind && !gfc_notify_std (GFC_STD_F2003, "%qs intrinsic "
- "with KIND argument at %L",
- gfc_current_intrinsic, &kind->where))
- return false;
-
return true;
}
diff --git a/gcc/testsuite/gfortran.dg/shape_10.f90 b/gcc/testsuite/gfortran.dg/shape_10.f90
new file mode 100644
index 00000000000..4943c21b1d2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/shape_10.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/102716
+
+program p
+ integer, parameter :: a(1) = shape([2], [1]) ! { dg-error "must be a scalar" }
+end
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PR fortran/102716 - ICE in gfc_validate_kind(): Got bad kind
2021-10-13 19:36 [PATCH] PR fortran/102716 - ICE in gfc_validate_kind(): Got bad kind Harald Anlauf
@ 2021-10-14 6:00 ` Thomas Koenig
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2021-10-14 6:00 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Hi Harald,
> another simple and obvious fix: we need to reorder the argument checks
> to the SHAPE intrinsic so that invalid KIND arguments can be detected.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
> As I consider this a safe fix, I'd like to backport to suitable branches.
Also OK for both.
Thanks a lot for the patch!
Best regards
Thomas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-14 6:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 19:36 [PATCH] PR fortran/102716 - ICE in gfc_validate_kind(): Got bad kind Harald Anlauf
2021-10-14 6:00 ` Thomas Koenig
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).