* [PATCH] Like the fix for PR 86045 but for modulo
@ 2018-08-09 14:12 Mark Eggleston
2018-08-09 15:19 ` Steve Kargl
0 siblings, 1 reply; 2+ messages in thread
From: Mark Eggleston @ 2018-08-09 14:12 UTC (permalink / raw)
To: kargl; +Cc: fortran
[-- Attachment #1: Type: text/plain, Size: 2014 bytes --]
Steven,
I'm sending this patch to you as it was found when a change to
gfc_simplify_mod caused the test for PR 86045 to fail.
Immediately after gfc_simplify_mod is gfc_simplify_modulo and is
similar. Substituting mod with modulo in the test file caused an
internal compiler error just like PR 86045.
Here is the back trace:
f951: internal compiler error: Segmentation fault
0xb7dedf crash_signal
   ../../gcc/gcc/toplev.c:325
0x6546e8 reduce_binary_ac
   ../../gcc/gcc/fortran/arith.c:1308
0x654682 reduce_binary_ac
   ../../gcc/gcc/fortran/arith.c:1295
0x6548cc reduce_binary
   ../../gcc/gcc/fortran/arith.c:1421
0x654b1b eval_intrinsic
   ../../gcc/gcc/fortran/arith.c:1596
0x6552be eval_intrinsic_f3
   ../../gcc/gcc/fortran/arith.c:1733
0x68bb75 simplify_intrinsic_op
   ../../gcc/gcc/fortran/expr.c:1158
0x68bb75 gfc_simplify_expr(gfc_expr*, int)
   ../../gcc/gcc/fortran/expr.c:1984
0x68af17 gfc_reduce_init_expr(gfc_expr*)
   ../../gcc/gcc/fortran/expr.c:2775
0x68db31 gfc_match_init_expr(gfc_expr**)
   ../../gcc/gcc/fortran/expr.c:2821
0x67b5b1 variable_decl
   ../../gcc/gcc/fortran/decl.c:2678
0x67b5b1 gfc_match_data_decl()
   ../../gcc/gcc/fortran/decl.c:5888
0x6d6429 match_word_omp_simd
   ../../gcc/gcc/fortran/parse.c:93
0x6d9b1e match_word
   ../../gcc/gcc/fortran/parse.c:376
0x6d9b1e decode_statement
   ../../gcc/gcc/fortran/parse.c:376
0x6dba44 next_free
   ../../gcc/gcc/fortran/parse.c:1234
0x6dba44 next_statement
   ../../gcc/gcc/fortran/parse.c:1466
0x6dd83c parse_spec
   ../../gcc/gcc/fortran/parse.c:3674
0x6df803 parse_progunit
   ../../gcc/gcc/fortran/parse.c:5671
0x6e0de4 gfc_parse_file()
   ../../gcc/gcc/fortran/parse.c:6211
Please find attached the patch to fix the problem.
regards,
Mark Eggleston
--
https://www.codethink.co.uk/privacy.html
[-- Attachment #2: modulo.patch --]
[-- Type: text/x-patch, Size: 3705 bytes --]
commit 757d9e0eb9a878ddc2d287fe90cfdd55a8d49c24
Author: Mark Eggleston <markeggleston@codethink.com>
Date: Thu Aug 9 14:33:08 2018 +0100
Like fix for PR 86045 but for modulo
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 2eb467a1915..1739281d6b7 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -5509,54 +5509,57 @@ gfc_simplify_modulo (gfc_expr *a, gfc_expr *p)
gfc_expr *result;
int kind;
- if (a->expr_type != EXPR_CONSTANT || p->expr_type != EXPR_CONSTANT)
+ /* First check p. */
+ if (p->expr_type != EXPR_CONSTANT)
return NULL;
- kind = a->ts.kind > p->ts.kind ? a->ts.kind : p->ts.kind;
- result = gfc_get_constant_expr (a->ts.type, kind, &a->where);
-
- switch (a->ts.type)
+ /* p shall not be 0. */
+ switch (p->ts.type)
{
case BT_INTEGER:
if (mpz_cmp_ui (p->value.integer, 0) == 0)
{
- /* Result is processor-dependent. This processor just opts
- to not handle it at all. */
- gfc_error ("Second argument of MODULO at %L is zero", &a->where);
- gfc_free_expr (result);
+ gfc_error ("Argument %qs of MODULO at %L shall not be zero",
+ "P", &p->where);
return &gfc_bad_expr;
}
- mpz_fdiv_r (result->value.integer, a->value.integer, p->value.integer);
-
break;
-
case BT_REAL:
if (mpfr_cmp_ui (p->value.real, 0) == 0)
{
- /* Result is processor-dependent. */
- gfc_error ("Second argument of MODULO at %L is zero", &p->where);
- gfc_free_expr (result);
+ gfc_error ("Argument %qs of MODULO at %L shall not be zero",
+ "P", &p->where);
return &gfc_bad_expr;
}
-
- gfc_set_model_kind (kind);
- mpfr_fmod (result->value.real, a->value.real, p->value.real,
- GFC_RND_MODE);
- if (mpfr_cmp_ui (result->value.real, 0) != 0)
- {
- if (mpfr_signbit (a->value.real) != mpfr_signbit (p->value.real))
- mpfr_add (result->value.real, result->value.real, p->value.real,
- GFC_RND_MODE);
- }
- else
- mpfr_copysign (result->value.real, result->value.real,
- p->value.real, GFC_RND_MODE);
break;
-
default:
gfc_internal_error ("gfc_simplify_modulo(): Bad arguments");
}
+ if (a->expr_type != EXPR_CONSTANT)
+ return NULL;
+
+ kind = a->ts.kind > p->ts.kind ? a->ts.kind : p->ts.kind;
+ result = gfc_get_constant_expr (a->ts.type, kind, &a->where);
+
+ if (a->ts.type == BT_INTEGER)
+ mpz_fdiv_r (result->value.integer, a->value.integer, p->value.integer);
+ else
+ {
+ gfc_set_model_kind (kind);
+ mpfr_fmod (result->value.real, a->value.real, p->value.real,
+ GFC_RND_MODE);
+ if (mpfr_cmp_ui (result->value.real, 0) != 0)
+ {
+ if (mpfr_signbit (a->value.real) != mpfr_signbit (p->value.real))
+ mpfr_add (result->value.real, result->value.real, p->value.real,
+ GFC_RND_MODE);
+ }
+ else
+ mpfr_copysign (result->value.real, result->value.real,
+ p->value.real, GFC_RND_MODE);
+ }
+
return range_check (result, "MODULO");
}
diff --git a/gcc/testsuite/gfortran.dg/modulo_const_array_p_is_zero.f90 b/gcc/testsuite/gfortran.dg/modulo_const_array_p_is_zero.f90
new file mode 100644
index 00000000000..1325d0f2e89
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/modulo_const_array_p_is_zero.f90
@@ -0,0 +1,6 @@
+program p
+ logical :: a(2) = (modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
+ integer :: b = count(modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
+ integer :: c = all(modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
+ integer :: d = any(modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
+end program
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Like the fix for PR 86045 but for modulo
2018-08-09 14:12 [PATCH] Like the fix for PR 86045 but for modulo Mark Eggleston
@ 2018-08-09 15:19 ` Steve Kargl
0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2018-08-09 15:19 UTC (permalink / raw)
To: Mark Eggleston; +Cc: kargl, fortran
Mark,
Thanks for taking an interesting in improving gfortran. At
the moment, I no longer contribute to gfortran development.
--
steve
On Thu, Aug 09, 2018 at 03:11:58PM +0100, Mark Eggleston wrote:
> Steven,
>
> I'm sending this patch to you as it was found when a change to
> gfc_simplify_mod caused the test for PR 86045 to fail.
>
> Immediately after gfc_simplify_mod is gfc_simplify_modulo and is
> similar. Substituting mod with modulo in the test file caused an
> internal compiler error just like PR 86045.
>
> Here is the back trace:
>
> f951: internal compiler error: Segmentation fault
> 0xb7dedf crash_signal
> Â Â Â ../../gcc/gcc/toplev.c:325
> 0x6546e8 reduce_binary_ac
> Â Â Â ../../gcc/gcc/fortran/arith.c:1308
> 0x654682 reduce_binary_ac
> Â Â Â ../../gcc/gcc/fortran/arith.c:1295
> 0x6548cc reduce_binary
> Â Â Â ../../gcc/gcc/fortran/arith.c:1421
> 0x654b1b eval_intrinsic
> Â Â Â ../../gcc/gcc/fortran/arith.c:1596
> 0x6552be eval_intrinsic_f3
> Â Â Â ../../gcc/gcc/fortran/arith.c:1733
> 0x68bb75 simplify_intrinsic_op
> Â Â Â ../../gcc/gcc/fortran/expr.c:1158
> 0x68bb75 gfc_simplify_expr(gfc_expr*, int)
> Â Â Â ../../gcc/gcc/fortran/expr.c:1984
> 0x68af17 gfc_reduce_init_expr(gfc_expr*)
> Â Â Â ../../gcc/gcc/fortran/expr.c:2775
> 0x68db31 gfc_match_init_expr(gfc_expr**)
> Â Â Â ../../gcc/gcc/fortran/expr.c:2821
> 0x67b5b1 variable_decl
> Â Â Â ../../gcc/gcc/fortran/decl.c:2678
> 0x67b5b1 gfc_match_data_decl()
> Â Â Â ../../gcc/gcc/fortran/decl.c:5888
> 0x6d6429 match_word_omp_simd
> Â Â Â ../../gcc/gcc/fortran/parse.c:93
> 0x6d9b1e match_word
> Â Â Â ../../gcc/gcc/fortran/parse.c:376
> 0x6d9b1e decode_statement
> Â Â Â ../../gcc/gcc/fortran/parse.c:376
> 0x6dba44 next_free
> Â Â Â ../../gcc/gcc/fortran/parse.c:1234
> 0x6dba44 next_statement
> Â Â Â ../../gcc/gcc/fortran/parse.c:1466
> 0x6dd83c parse_spec
> Â Â Â ../../gcc/gcc/fortran/parse.c:3674
> 0x6df803 parse_progunit
> Â Â Â ../../gcc/gcc/fortran/parse.c:5671
> 0x6e0de4 gfc_parse_file()
> Â Â Â ../../gcc/gcc/fortran/parse.c:6211
>
> Please find attached the patch to fix the problem.
>
> regards,
>
> Mark Eggleston
>
> --
> https://www.codethink.co.uk/privacy.html
>
> commit 757d9e0eb9a878ddc2d287fe90cfdd55a8d49c24
> Author: Mark Eggleston <markeggleston@codethink.com>
> Date: Thu Aug 9 14:33:08 2018 +0100
>
> Like fix for PR 86045 but for modulo
>
> diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
> index 2eb467a1915..1739281d6b7 100644
> --- a/gcc/fortran/simplify.c
> +++ b/gcc/fortran/simplify.c
> @@ -5509,54 +5509,57 @@ gfc_simplify_modulo (gfc_expr *a, gfc_expr *p)
> gfc_expr *result;
> int kind;
>
> - if (a->expr_type != EXPR_CONSTANT || p->expr_type != EXPR_CONSTANT)
> + /* First check p. */
> + if (p->expr_type != EXPR_CONSTANT)
> return NULL;
>
> - kind = a->ts.kind > p->ts.kind ? a->ts.kind : p->ts.kind;
> - result = gfc_get_constant_expr (a->ts.type, kind, &a->where);
> -
> - switch (a->ts.type)
> + /* p shall not be 0. */
> + switch (p->ts.type)
> {
> case BT_INTEGER:
> if (mpz_cmp_ui (p->value.integer, 0) == 0)
> {
> - /* Result is processor-dependent. This processor just opts
> - to not handle it at all. */
> - gfc_error ("Second argument of MODULO at %L is zero", &a->where);
> - gfc_free_expr (result);
> + gfc_error ("Argument %qs of MODULO at %L shall not be zero",
> + "P", &p->where);
> return &gfc_bad_expr;
> }
> - mpz_fdiv_r (result->value.integer, a->value.integer, p->value.integer);
> -
> break;
> -
> case BT_REAL:
> if (mpfr_cmp_ui (p->value.real, 0) == 0)
> {
> - /* Result is processor-dependent. */
> - gfc_error ("Second argument of MODULO at %L is zero", &p->where);
> - gfc_free_expr (result);
> + gfc_error ("Argument %qs of MODULO at %L shall not be zero",
> + "P", &p->where);
> return &gfc_bad_expr;
> }
> -
> - gfc_set_model_kind (kind);
> - mpfr_fmod (result->value.real, a->value.real, p->value.real,
> - GFC_RND_MODE);
> - if (mpfr_cmp_ui (result->value.real, 0) != 0)
> - {
> - if (mpfr_signbit (a->value.real) != mpfr_signbit (p->value.real))
> - mpfr_add (result->value.real, result->value.real, p->value.real,
> - GFC_RND_MODE);
> - }
> - else
> - mpfr_copysign (result->value.real, result->value.real,
> - p->value.real, GFC_RND_MODE);
> break;
> -
> default:
> gfc_internal_error ("gfc_simplify_modulo(): Bad arguments");
> }
>
> + if (a->expr_type != EXPR_CONSTANT)
> + return NULL;
> +
> + kind = a->ts.kind > p->ts.kind ? a->ts.kind : p->ts.kind;
> + result = gfc_get_constant_expr (a->ts.type, kind, &a->where);
> +
> + if (a->ts.type == BT_INTEGER)
> + mpz_fdiv_r (result->value.integer, a->value.integer, p->value.integer);
> + else
> + {
> + gfc_set_model_kind (kind);
> + mpfr_fmod (result->value.real, a->value.real, p->value.real,
> + GFC_RND_MODE);
> + if (mpfr_cmp_ui (result->value.real, 0) != 0)
> + {
> + if (mpfr_signbit (a->value.real) != mpfr_signbit (p->value.real))
> + mpfr_add (result->value.real, result->value.real, p->value.real,
> + GFC_RND_MODE);
> + }
> + else
> + mpfr_copysign (result->value.real, result->value.real,
> + p->value.real, GFC_RND_MODE);
> + }
> +
> return range_check (result, "MODULO");
> }
>
> diff --git a/gcc/testsuite/gfortran.dg/modulo_const_array_p_is_zero.f90 b/gcc/testsuite/gfortran.dg/modulo_const_array_p_is_zero.f90
> new file mode 100644
> index 00000000000..1325d0f2e89
> --- /dev/null
> +++ b/gcc/testsuite/gfortran.dg/modulo_const_array_p_is_zero.f90
> @@ -0,0 +1,6 @@
> +program p
> + logical :: a(2) = (modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
> + integer :: b = count(modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
> + integer :: c = all(modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
> + integer :: d = any(modulo([2,3],0) == 0) ! { dg-error "shall not be zero" }
> +end program
--
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-08-09 15:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-09 14:12 [PATCH] Like the fix for PR 86045 but for modulo Mark Eggleston
2018-08-09 15:19 ` Steve Kargl
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).