* [Bug fortran/104352] ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.)
2022-02-02 18:48 [Bug fortran/104352] New: ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.) gscfq@t-online.de
@ 2022-02-02 18:50 ` gscfq@t-online.de
2022-05-25 20:37 ` kargl at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: gscfq@t-online.de @ 2022-02-02 18:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104352
G. Steinmetz <gscfq@t-online.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ice-on-invalid-code
--- Comment #1 from G. Steinmetz <gscfq@t-online.de> ---
Intrinsic "any" in above test files can be replaced with e.g.
$ cat za1.f90
program p
integer, parameter :: a(0) = 1
print *, all(a(1:1) == 1)
print *, any(a(1:1) == 1)
print *, count(a(1:1) == 1)
print *, is_contiguous(a(1:1) == 1)
print *, parity(a(1:1) == 1)
print *, shape(a(1:1) == 1)
print *, size(a(1:1) == 1)
print *, ubound(a(1:1) == 1)
end
Other variants also affect intrinsics like iany, iall, ...
$ cat zb1.f90
program p
integer, parameter :: a(0) = 1
print *, iall(a(1:1))
print *, iany(a(1:1))
print *, iparity(a(1:1))
print *, maxval(a(1:1))
print *, minval(a(1:1))
print *, product(a(1:1))
print *, sum(a(1:1))
end
Another modification pattern hits minloc, macloc, ...
$ cat zc1.f90
program p
integer, parameter :: a(0) = 1
print *, ibclr(a(1:1), 1)
print *, ibset(a(1:1), 1)
print *, max(a(1:1), 1)
print *, max0(a(1:1), 1)
print *, maxloc(a(1:1), 1)
print *, min(a(1:1), 1)
print *, min0(a(1:1), 1)
print *, minloc(a(1:1), 1)
end
or ...
$ cat zd1.f90
program p
real, parameter :: a(0) = 1
print *, dot_product(a(1:1), a(1:1))
print *, norm2(a(1:1))
end
subroutine s
complex, parameter :: a(0) = 1
print *, dot_product(a(1:1), a(1:1))
print *, conjg(a(1:1))
end
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/104352] ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.)
2022-02-02 18:48 [Bug fortran/104352] New: ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.) gscfq@t-online.de
2022-02-02 18:50 ` [Bug fortran/104352] " gscfq@t-online.de
@ 2022-05-25 20:37 ` kargl at gcc dot gnu.org
2022-10-21 20:18 ` anlauf at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-05-25 20:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104352
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-05-25
Priority|P3 |P4
Ever confirmed|0 |1
CC| |kargl at gcc dot gnu.org
Status|UNCONFIRMED |NEW
--- Comment #2 from kargl at gcc dot gnu.org ---
It make absolutely no sense to emit a warning when gfortran
detects an out-of-bounds array index. This patch fixes the
ICE and fixes the second error message to report that it is
the upper bound not the lower bound that errors out.
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 2ebf076f730..52a394db26a 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -4754,19 +4754,19 @@ check_dimension (int i, gfc_array_ref *ar,
gfc_array_spec *as)
{
if (compare_bound (AR_START, as->lower[i]) == CMP_LT)
{
- gfc_warning (0, "Lower array reference at %L is out of bounds "
+ gfc_error ("Lower array reference at %L is out of bounds "
"(%ld < %ld) in dimension %d", &ar->c_where[i],
mpz_get_si (AR_START->value.integer),
mpz_get_si (as->lower[i]->value.integer), i+1);
- return true;
+ return false;
}
if (compare_bound (AR_START, as->upper[i]) == CMP_GT)
{
- gfc_warning (0, "Lower array reference at %L is out of bounds "
+ gfc_error ("Upper array reference at %L is out of bounds "
"(%ld > %ld) in dimension %d", &ar->c_where[i],
mpz_get_si (AR_START->value.integer),
mpz_get_si (as->upper[i]->value.integer), i+1);
- return true;
+ return false;
}
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/104352] ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.)
2022-02-02 18:48 [Bug fortran/104352] New: ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.) gscfq@t-online.de
2022-02-02 18:50 ` [Bug fortran/104352] " gscfq@t-online.de
2022-05-25 20:37 ` kargl at gcc dot gnu.org
@ 2022-10-21 20:18 ` anlauf at gcc dot gnu.org
2023-05-17 19:56 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-21 20:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104352
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gcc dot gnu.org
--- Comment #3 from anlauf at gcc dot gnu.org ---
There are also other PRs with ICEs and array bounds violation which might
be fixed by turning warnings into errors.
The patch in comment#2 misses another pair of checks in check_dimension
that need to be adjusted, including the mixup Lower <-> Upper.
However, the resulting modification leads to regressions in the following
testcases:
gfortran.dg/bounds_check_3.f90
gfortran.dg/bounds_check_11.f90
gfortran.dg/goacc/subarrays.f95
gfortran.dg/gomp/map-1.f90
I think we need to know which kind of abuse of array indices we want to
accept for legacy code, of which there might be plenty in the wild.
Potential candidates where there should be no error, maybe even no warning:
- assumed-size arrays
- arrays whose last dimension is 1 (only for -std=legacy (?))
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/104352] ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.)
2022-02-02 18:48 [Bug fortran/104352] New: ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.) gscfq@t-online.de
` (2 preceding siblings ...)
2022-10-21 20:18 ` anlauf at gcc dot gnu.org
@ 2023-05-17 19:56 ` cvs-commit at gcc dot gnu.org
2023-05-17 20:00 ` anlauf at gcc dot gnu.org
2024-04-02 17:07 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-17 19:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104352
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:7bafe652dba9167b65e7b5ef24e77eceb49709ba
commit r14-950-g7bafe652dba9167b65e7b5ef24e77eceb49709ba
Author: Harald Anlauf <anlauf@gmx.de>
Date: Wed May 17 20:39:18 2023 +0200
Fortran: set shape of initializers of zero-sized arrays [PR95374,PR104352]
gcc/fortran/ChangeLog:
PR fortran/95374
PR fortran/104352
* decl.cc (add_init_expr_to_sym): Set shape of initializer also for
zero-sized arrays, so that bounds violations can be detected later.
gcc/testsuite/ChangeLog:
PR fortran/95374
PR fortran/104352
* gfortran.dg/zero_sized_13.f90: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/104352] ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.)
2022-02-02 18:48 [Bug fortran/104352] New: ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.) gscfq@t-online.de
` (3 preceding siblings ...)
2023-05-17 19:56 ` cvs-commit at gcc dot gnu.org
@ 2023-05-17 20:00 ` anlauf at gcc dot gnu.org
2024-04-02 17:07 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-05-17 20:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104352
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Target Milestone|--- |14.0
Resolution|--- |FIXED
--- Comment #5 from anlauf at gcc dot gnu.org ---
Fixed on mainline for gcc-14. Closing.
Thanks for the report!
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/104352] ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.)
2022-02-02 18:48 [Bug fortran/104352] New: ICE in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.cc:4481 (etc.) gscfq@t-online.de
` (4 preceding siblings ...)
2023-05-17 20:00 ` anlauf at gcc dot gnu.org
@ 2024-04-02 17:07 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-02 17:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104352
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:0dd82c0fba660775ff76ae27077a67f2f1358920
commit r13-8557-g0dd82c0fba660775ff76ae27077a67f2f1358920
Author: Harald Anlauf <anlauf@gmx.de>
Date: Wed May 17 20:39:18 2023 +0200
Fortran: set shape of initializers of zero-sized arrays [PR95374,PR104352]
gcc/fortran/ChangeLog:
PR fortran/95374
PR fortran/104352
* decl.cc (add_init_expr_to_sym): Set shape of initializer also for
zero-sized arrays, so that bounds violations can be detected later.
gcc/testsuite/ChangeLog:
PR fortran/95374
PR fortran/104352
* gfortran.dg/zero_sized_13.f90: New test.
(cherry picked from commit 7bafe652dba9167b65e7b5ef24e77eceb49709ba)
^ permalink raw reply [flat|nested] 7+ messages in thread