* [PATCH] PR fortran 88116,88467 -- Catch array constructor errors
@ 2018-12-14 0:27 Steve Kargl
0 siblings, 0 replies; 4+ messages in thread
From: Steve Kargl @ 2018-12-14 0:27 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1014 bytes --]
The attached patch has been regression tested on
x86_64-*-freebsd. It fixes to PR. Both PR are related
to errors in array constructors. PR fortran/88116 was not
reporting an error on type mismatches with nested array
constructors. PR fortran/88467 was silently accepting
a CHARACTER entity within nested array constructors.
OK to commit?
2018-12-13 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/88116
PR fortran/88467
* array.c (gfc_match_array_constructor): Check return value of
gfc_convert_type(). Skip constructor elements with BT_UNKNOWN,
which need to go through resolution.
* intrinsic.c (gfc_convert_type_warn): Return early if the types
martch (i.e., no conversion is required).
* simplify.c (gfc_convert_constant): Remove a gfc_internal_error,
and return gfc_bad_expr.
2018-12-13 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/88116
* gfortran.dg/pr88116_1.f90: New test.
* gfortran.dg/pr88116_2.f90: Ditto.
PR fortran/88467
* gfortran.dg/pr88467.f90: New test.
--
Steve
[-- Attachment #2: pr88467.diff --]
[-- Type: text/x-diff, Size: 2832 bytes --]
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c (revision 267063)
+++ gcc/fortran/array.c (working copy)
@@ -1246,7 +1246,9 @@ done:
{
c = gfc_constructor_first (head);
for (; c; c = gfc_constructor_next (c))
- gfc_convert_type (c->expr, &ts, 1);
+ if (!gfc_convert_type (c->expr, &ts, 1)
+ && c->expr->ts.type != BT_UNKNOWN)
+ return MATCH_ERROR;
}
}
else
Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c (revision 267063)
+++ gcc/fortran/intrinsic.c (working copy)
@@ -5030,6 +5030,13 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *t
if (expr->ts.type == BT_UNKNOWN)
goto bad;
+ /* In building an array constructor, gfortran can end up here when no
+ conversion is required for an intrinsic type. We need to let derive
+ types drop through. */
+ if (from_ts.type != BT_DERIVED
+ && (from_ts.type == ts->type && from_ts.kind == ts->kind))
+ return true;
+
if (expr->ts.type == BT_DERIVED && ts->type == BT_DERIVED
&& gfc_compare_types (&expr->ts, ts))
return true;
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c (revision 267063)
+++ gcc/fortran/simplify.c (working copy)
@@ -8360,7 +8360,7 @@ gfc_convert_constant (gfc_expr *e, bt type, int kind)
default:
oops:
- gfc_internal_error ("gfc_convert_constant(): Unexpected type");
+ return &gfc_bad_expr;
}
result = NULL;
Index: gcc/testsuite/gfortran.dg/pr88116_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr88116_1.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr88116_1.f90 (working copy)
@@ -0,0 +1,4 @@
+! { dg-do compile }
+program p
+ print *, [integer :: 1, [integer(8) :: 2, ['3']]] ! { dg-error "Can't convert" }
+end
Index: gcc/testsuite/gfortran.dg/pr88116_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr88116_2.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr88116_2.f90 (working copy)
@@ -0,0 +1,7 @@
+! { dg-do run }
+program p
+ real :: a(2) = [real :: 1, [integer :: (real(k), k=2,1), 2]]
+ real :: b(1) = [real :: [integer :: (dble(k), k=1,0), 2]]
+ if (a(1) /= 1. .or. a(2) /= 2. .or. b(1) /= 2.) stop 1
+end
+
Index: gcc/testsuite/gfortran.dg/pr88467.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr88467.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr88467.f90 (working copy)
@@ -0,0 +1,4 @@
+! { dg-do compile }
+program foo
+ print *, [integer :: 1, [integer(8) :: 2, '3']] ! { dg-error "Can\'t convert" }
+end program foo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PR fortran 88116,88467 -- Catch array constructor errors
2018-12-16 15:46 ` Steve Kargl
@ 2018-12-17 18:07 ` Segher Boessenkool
0 siblings, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2018-12-17 18:07 UTC (permalink / raw)
To: Steve Kargl; +Cc: Dominique d'Humières, gfortran, gcc-patches
On Sun, Dec 16, 2018 at 07:46:45AM -0800, Steve Kargl wrote:
> On Sun, Dec 16, 2018 at 11:45:11AM +0100, Dominique d'Humières wrote:
> > Hi Steve,
> >
> > The patch works as expected.
> >
> > Is "Can\ât " instead of "Canât " really necessary?
> >
>
> I don't remember how dejagnu handles quotes in the
> regex expression. "Can\'t" seems to work (for me).
> If you want to change it, go ahead. Personally, I
> would prefer "Cannot".
A backslash in a double-quoted string is handled by backslash-substitution,
before it is ever seen as a regexp. "\'" is exactly the same as "'".
In a braced string it does not get backslash-substitution and then it _is_
handled by the regular expression parsing, but again, as RE {\'} is exactly
the same as {'}.
Segher
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PR fortran 88116,88467 -- Catch array constructor errors
2018-12-16 10:45 Dominique d'Humières
@ 2018-12-16 15:46 ` Steve Kargl
2018-12-17 18:07 ` Segher Boessenkool
0 siblings, 1 reply; 4+ messages in thread
From: Steve Kargl @ 2018-12-16 15:46 UTC (permalink / raw)
To: Dominique d'Humières; +Cc: gfortran, gcc-patches
On Sun, Dec 16, 2018 at 11:45:11AM +0100, Dominique d'Humières wrote:
> Hi Steve,
>
> The patch works as expected.
>
> Is "Can\ât " instead of "Canât " really necessary?
>
I don't remember how dejagnu handles quotes in the
regex expression. "Can\'t" seems to work (for me).
If you want to change it, go ahead. Personally, I
would prefer "Cannot".
--
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PR fortran 88116,88467 -- Catch array constructor errors
@ 2018-12-16 10:45 Dominique d'Humières
2018-12-16 15:46 ` Steve Kargl
0 siblings, 1 reply; 4+ messages in thread
From: Dominique d'Humières @ 2018-12-16 10:45 UTC (permalink / raw)
To: Steve Kargl; +Cc: gfortran, gcc-patches
Hi Steve,
The patch works as expected.
Is "Can\’t " instead of "Can’t " really necessary?
Thanks for the patch,
Dominique
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-12-17 18:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14 0:27 [PATCH] PR fortran 88116,88467 -- Catch array constructor errors Steve Kargl
2018-12-16 10:45 Dominique d'Humières
2018-12-16 15:46 ` Steve Kargl
2018-12-17 18:07 ` Segher Boessenkool
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).