[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-24 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

Martin Liška  changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution|--- |FIXED

--- Comment #13 from Martin Liška  ---
Fixed now, I'm not planning to make backports.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-24 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #12 from Martin Liška  ---
Author: marxin
Date: Thu Oct 24 08:49:02 2019
New Revision: 277367

URL: https://gcc.gnu.org/viewcvs?rev=277367&root=gcc&view=rev
Log:
Fix another UBSAN in Fortran coarray.

2019-10-24  Martin Liska  

PR fortran/92174
* array.c (gfc_resolve_array_spec): Break the loop
for out of bounds index.
* resolve.c (is_non_constant_shape_array): Likewise.

Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/array.c
trunk/gcc/fortran/resolve.c

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-24 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

Martin Liška  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
   Last reconfirmed||2019-10-24
 Resolution|FIXED   |---
   Assignee|kargl at gcc dot gnu.org   |marxin at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #11 from Martin Liška  ---
I see two more places where similar UBSAN happens, I'm testing a patch.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-23 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #10 from Martin Liška  ---
(In reply to kargl from comment #9)
> fixed on 9-branch and trunk.

Thank you for the fix.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

kargl at gcc dot gnu.org changed:

   What|Removed |Added

   Priority|P3  |P4
 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED
   Assignee|unassigned at gcc dot gnu.org  |kargl at gcc dot gnu.org
   Target Milestone|--- |9.3

--- Comment #9 from kargl at gcc dot gnu.org ---
fixed on 9-branch and trunk.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #8 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Tue Oct 22 18:38:30 2019
New Revision: 277298

URL: https://gcc.gnu.org/viewcvs?rev=277298&root=gcc&view=rev
Log:
2019-10-22  Steven G. Kargl  

PR fortran/92174
* decl.c (attr_decl1): Move check for F2018:C822 from here ...
* array.c (gfc_set_array_spec): ... to here. 

Modified:
branches/gcc-9-branch/gcc/fortran/ChangeLog
branches/gcc-9-branch/gcc/fortran/array.c
branches/gcc-9-branch/gcc/fortran/decl.c

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #7 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Tue Oct 22 18:18:59 2019
New Revision: 277297

URL: https://gcc.gnu.org/viewcvs?rev=277297&root=gcc&view=rev
Log:
2019-10-22  Steven G. Kargl  

PR fortran/92174
* decl.c (attr_decl1): Move check for F2018:C822 from here ...
* array.c (gfc_set_array_spec): ... to here. 

Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/array.c
trunk/gcc/fortran/decl.c

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread sgk at troutmask dot apl.washington.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #6 from Steve Kargl  ---
On Tue, Oct 22, 2019 at 02:56:01PM +, marxin at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174
> 
> --- Comment #5 from Martin Liška  ---
> > Problem is that the compiler invokes an undefined behaviour for the source 
> file.
> 
> More precisely, it's an out of bounds array access.
> 

Which is irrelevant as the gfortran diagnosis the
issue, issues an error meesage, and exits.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #5 from Martin Liška  ---
> Problem is that the compiler invokes an undefined behaviour for the source 
file.

More precisely, it's an out of bounds array access.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #4 from Martin Liška  ---
(In reply to Steve Kargl from comment #3)
> On Tue, Oct 22, 2019 at 02:14:55PM +, marxin at gcc dot gnu.org wrote:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174
> > 
> > --- Comment #2 from Martin Liška  ---
> > (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  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.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread sgk at troutmask dot apl.washington.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #3 from Steve Kargl  ---
On Tue, Oct 22, 2019 at 02:14:55PM +, marxin at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174
> 
> --- Comment #2 from Martin Liška  ---
> (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?

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

--- Comment #2 from Martin Liška  ---
(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.

[Bug fortran/92174] runtime error: index 15 out of bounds for type 'gfc_expr *[15]

2019-10-22 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92174

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 CC||kargl at gcc dot gnu.org

--- Comment #1 from kargl at gcc dot gnu.org ---
(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.