[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]
marxin at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Oct 22 14:55:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174
--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Steve Kargl from comment #3)
> On Tue, Oct 22, 2019 at 02:14:55PM +0000, marxin at gcc dot gnu.org wrote:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174
> >
> > --- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
> > (In reply to kargl from comment #1)
> > > (In reply to Martin Liška from comment #0)
> > > > Happens with UBSAN build in:
> > > >
> > > > $ ./xgcc -B.
> > > > /home/marxin/Programming/gcc/gcc/testsuite/gfortran.dg/pr91802.f90
> > > > -fcoarray=single
> > > > ../../gcc/fortran/array.c:867:36: runtime error: index 15 out of bounds for
> > > > type 'gfc_expr *[15]'
> > >
> > >
> > > What are you doing? pr91802.f90 is a compile time test.
> > > It cannot generate a runtime error.
> >
> > It's a runtime error of the GCC compiler that compiles the test-case ;)
> > The error message is a bit misleading.
> >
>
> So, what does your tool do? gfortran correctly diagnosis
> that rank+corank > 15, issues an error, and exits. What is
> the problem?
Problem is that the compiler invokes an undefined behaviour for the source
file.
You can see the same with the following patch:
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 427110bee74..166caca8347 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -864,6 +864,7 @@ gfc_set_array_spec (gfc_symbol *sym, gfc_array_spec *as,
locus *error_loc)
sym->as->corank = as->corank;
for (i = 0; i < as->corank; i++)
{
+ gcc_assert (sym->as->rank + i < GFC_MAX_DIMENSIONS);
sym->as->lower[sym->as->rank + i] = as->lower[i];
sym->as->upper[sym->as->rank + i] = as->upper[i];
}
$ ./xgcc -B. /home/marxin/Programming/gcc/gcc/testsuite/gfortran.dg/pr91802.f90
-fcoarray=single
f951: internal compiler error: in gfc_set_array_spec, at fortran/array.c:867
0x880e62 gfc_set_array_spec(gfc_symbol*, gfc_array_spec*, locus*)
/home/marxin/Programming/gcc/gcc/fortran/array.c:867
0x8b3f6d attr_decl1
/home/marxin/Programming/gcc/gcc/fortran/decl.c:8521
0x8b4114 attr_decl
/home/marxin/Programming/gcc/gcc/fortran/decl.c:8582
0x8b46f0 gfc_match_codimension()
/home/marxin/Programming/gcc/gcc/fortran/decl.c:8855
0x93dd54 match_word
/home/marxin/Programming/gcc/gcc/fortran/parse.c:65
0x93efcb decode_statement
/home/marxin/Programming/gcc/gcc/fortran/parse.c:464
0x944185 next_free
/home/marxin/Programming/gcc/gcc/fortran/parse.c:1272
0x944727 next_statement
/home/marxin/Programming/gcc/gcc/fortran/parse.c:1504
0x947bf0 parse_spec
/home/marxin/Programming/gcc/gcc/fortran/parse.c:3902
0x94b747 parse_module
/home/marxin/Programming/gcc/gcc/fortran/parse.c:6085
0x94c15b gfc_parse_file()
/home/marxin/Programming/gcc/gcc/fortran/parse.c:6390
0x9ad167 gfc_be_parse_file
/home/marxin/Programming/gcc/gcc/fortran/f95-lang.c:208
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Note that sym->as->lower is defined as:
struct gfc_expr *lower[GFC_MAX_DIMENSIONS], *upper[GFC_MAX_DIMENSIONS];
Hope it's clear now? Thanks.
More information about the Gcc-bugs
mailing list