* [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER
@ 2015-10-26 1:18 Steve Kargl
2015-10-26 8:51 ` FX
0 siblings, 1 reply; 7+ messages in thread
From: Steve Kargl @ 2015-10-26 1:18 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 445 bytes --]
The attached patch fixes a segfault in f951 for some poorly
written invalid code. See the testcase for the code in
question. Built and tested on i386-*-freebsd. Ok to commit?
2015-10-25 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/36192
* array.c (gfc_ref_dimen_size): Check for BT_INTEGER before calling
mpz_set.
2015-10-25 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/36192
* gfortran.dg/pr36192.f90: New test.
--
Steve
[-- Attachment #2: pr36192.diff --]
[-- Type: text/x-diff, Size: 1497 bytes --]
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c (revision 229301)
+++ gcc/fortran/array.c (working copy)
@@ -2208,7 +2208,8 @@ gfc_ref_dimen_size (gfc_array_ref *ar, i
if (ar->start[dimen] == NULL)
{
if (ar->as->lower[dimen] == NULL
- || ar->as->lower[dimen]->expr_type != EXPR_CONSTANT)
+ || ar->as->lower[dimen]->expr_type != EXPR_CONSTANT
+ || ar->as->lower[dimen]->ts.type != BT_INTEGER)
goto cleanup;
mpz_set (lower, ar->as->lower[dimen]->value.integer);
}
@@ -2222,7 +2223,8 @@ gfc_ref_dimen_size (gfc_array_ref *ar, i
if (ar->end[dimen] == NULL)
{
if (ar->as->upper[dimen] == NULL
- || ar->as->upper[dimen]->expr_type != EXPR_CONSTANT)
+ || ar->as->upper[dimen]->expr_type != EXPR_CONSTANT
+ || ar->as->upper[dimen]->ts.type != BT_INTEGER)
goto cleanup;
mpz_set (upper, ar->as->upper[dimen]->value.integer);
}
Index: gcc/testsuite/gfortran.dg/pr36192.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr36192.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/pr36192.f90 (working copy)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/36192.f90
+!
+program three_body
+ real, parameter :: n = 2, d = 2
+ real, dimension(n,d) :: x ! { dg-error "of INTEGER type|of INTEGER type" }
+ x(1,:) = (/ 1.0, 0.0 /)
+end program three_body
+! { dg-prune-output "have constant shape" }
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER
2015-10-26 1:18 [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER Steve Kargl
@ 2015-10-26 8:51 ` FX
2015-10-26 13:48 ` Steve Kargl
0 siblings, 1 reply; 7+ messages in thread
From: FX @ 2015-10-26 8:51 UTC (permalink / raw)
To: Steve Kargl; +Cc: fortran, gcc-patches
> 2015-10-25 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/36192
> * array.c (gfc_ref_dimen_size): Check for BT_INTEGER before calling
> mpz_set.
>
>
> 2015-10-25 Steven G. Kargl <kargl@gcc.gnu.org>
>
> PR fortran/36192
> * gfortran.dg/pr36192.f90: New test.
OK. But I don’t understand why the testcase’s dg-error pattern has this form: a regex “or” (|) of two identical strings?
FX
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER
2015-10-26 8:51 ` FX
@ 2015-10-26 13:48 ` Steve Kargl
2015-10-26 14:47 ` FX
0 siblings, 1 reply; 7+ messages in thread
From: Steve Kargl @ 2015-10-26 13:48 UTC (permalink / raw)
To: FX; +Cc: fortran, gcc-patches
On Mon, Oct 26, 2015 at 09:49:10AM +0100, FX wrote:
> > 2015-10-25 Steven G. Kargl <kargl@gcc.gnu.org>
> >
> > PR fortran/36192
> > * array.c (gfc_ref_dimen_size): Check for BT_INTEGER before calling
> > mpz_set.
> >
> >
> > 2015-10-25 Steven G. Kargl <kargl@gcc.gnu.org>
> >
> > PR fortran/36192
> > * gfortran.dg/pr36192.f90: New test.
>
> OK. But I don???t understand why the testcase???s dg-error pattern has this form: a regex ???or??? (|) of two identical strings?
>
Because the code issues two errors, one for each dimension.
I thought testing for the third (which I prune) to be
excessive.
laptop-kargl:kargl[202] gfc -c pr36192.f90
pr36192.f90:6:18:
real, dimension(n,d) :: x ! { dg-error "of INTEGER type|of INTEGER type" }
1
Error: Expression at (1) must be of INTEGER type, found REAL
pr36192.f90:6:20:
real, dimension(n,d) :: x ! { dg-error "of INTEGER type|of INTEGER type" }
1
Error: Expression at (1) must be of INTEGER type, found REAL
pr36192.f90:6:27:
real, dimension(n,d) :: x ! { dg-error "of INTEGER type|of INTEGER type" }
1
Error: The module or main program array 'x' at (1) must have constant shape
--
Steve
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER
2015-10-26 13:48 ` Steve Kargl
@ 2015-10-26 14:47 ` FX
2015-10-26 16:13 ` Steve Kargl
0 siblings, 1 reply; 7+ messages in thread
From: FX @ 2015-10-26 14:47 UTC (permalink / raw)
To: Steve Kargl; +Cc: fortran, gcc-patches
> Because the code issues two errors, one for each dimension.
Then shouldn’t it be “string.*string” to match two occurences of the string, with some stuff (incl. newline) in the middle?
FX
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER
2015-10-26 14:47 ` FX
@ 2015-10-26 16:13 ` Steve Kargl
0 siblings, 0 replies; 7+ messages in thread
From: Steve Kargl @ 2015-10-26 16:13 UTC (permalink / raw)
To: FX; +Cc: fortran, gcc-patches
On Mon, Oct 26, 2015 at 03:43:37PM +0100, FX wrote:
> > Because the code issues two errors, one for each dimension.
>
> Then shouldn???t it be ???string.*string??? to match
> two occurences of the string, with some stuff (incl. newline) in the middle?
>
I don't know dejagnu well enough to know if some other regex pattern
would capture all 3 errors. I'm simply using the advice given on
the wiki: https://gcc.gnu.org/wiki/TestCaseWriting
If you have a better pattern, I'm more than willing to change the
testcase.
The point of the testcase isn't to see if 3 errors messages or even
1 error message is issued. The testcase demonstrates that the segfault
in F951 (caused by calling mpz_set with an invalid mpz_t) does not happen.
--
Steve
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER
2015-10-26 10:15 Dominique d'Humières
@ 2015-10-26 16:30 ` Dominique d'Humières
0 siblings, 0 replies; 7+ messages in thread
From: Dominique d'Humières @ 2015-10-26 16:30 UTC (permalink / raw)
To: Steve Kargl; +Cc: FX, gfortran, gcc-patches
> … . The testcase demonstrates that the segfault in F951 (caused by calling
> mpz_set with an invalid mpz_t) does not happen.
If I am not mistaken, the test compiles without the patch (with different messages at least on x86_64-apple-darwin14
/opt/gcc/work/gcc/testsuite/gfortran.dg/pr36192.f90:6:18:
real, dimension(n,d) :: x ! { dg-error "of INTEGER type|of INTEGER type" }
1
Error: Expression at (1) must be of INTEGER type, found REAL
/opt/gcc/work/gcc/testsuite/gfortran.dg/pr36192.f90:6:20:
real, dimension(n,d) :: x ! { dg-error "of INTEGER type|of INTEGER type" }
1
Error: Expression at (1) must be of INTEGER type, found REAL
/opt/gcc/work/gcc/testsuite/gfortran.dg/pr36192.f90:6:27:
real, dimension(n,d) :: x ! { dg-error "of INTEGER type|of INTEGER type" }
1
Error: The module or main program array 'x' at (1) must have constant shape
/opt/gcc/work/gcc/testsuite/gfortran.dg/pr36192.f90:7:2:
x(1,:) = (/ 1.0, 0.0 /)
1
Error: Different shape for array assignment at (1) on dimension 1 (0 and 2)
Dominique
> Le 26 oct. 2015 à 11:15, Dominique d'Humières <dominiq@lps.ens.fr> a écrit :
>
> With the patch compiling the original test still gives
>
> …
> pr36192.f90:39:10:
>
> x_n, v_n, & ! Configuration at t+dt with step dt
> 1
> Error: The module or main program array 'x_n' at (1) must have constant shape
> f951: internal compiler error: Segmentation fault: 11
>
> Dominique
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER
@ 2015-10-26 10:15 Dominique d'Humières
2015-10-26 16:30 ` Dominique d'Humières
0 siblings, 1 reply; 7+ messages in thread
From: Dominique d'Humières @ 2015-10-26 10:15 UTC (permalink / raw)
To: Steve Kargl; +Cc: FX, gfortran, gcc-patches
With the patch compiling the original test still gives
…
pr36192.f90:39:10:
x_n, v_n, & ! Configuration at t+dt with step dt
1
Error: The module or main program array 'x_n' at (1) must have constant shape
f951: internal compiler error: Segmentation fault: 11
Dominique
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-10-26 16:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-26 1:18 [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER Steve Kargl
2015-10-26 8:51 ` FX
2015-10-26 13:48 ` Steve Kargl
2015-10-26 14:47 ` FX
2015-10-26 16:13 ` Steve Kargl
2015-10-26 10:15 Dominique d'Humières
2015-10-26 16:30 ` Dominique d'Humières
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).