public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/111853] New: f951: Segmentation fault at gfc_expression_rank
@ 2023-10-17 21:47 canu7 at yahoo dot es
  2023-10-18  5:49 ` [Bug fortran/111853] " kargl at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: canu7 at yahoo dot es @ 2023-10-17 21:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111853

            Bug ID: 111853
           Summary: f951: Segmentation fault at gfc_expression_rank
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: canu7 at yahoo dot es
  Target Milestone: ---

I'm using the following gfortran version on Arch Linux:

```
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-libstdcxx-backtrace
--enable-link-serialization=1 --enable-linker-build-id --enable-lto
--enable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.1 20230801 (GCC) 
```

Here is the reduced code that causes the segmentation fault:

```Fortran
  TYPE vec_rect_2D_real_acc
    INTEGER    arr
    END TYPE 
CLASS(vec_rect_2D_real_acc)  rvec
    ASSOCIATE (arr=>rvec%arr)
          arr(arr*arr
```

This is the result of executing it directly with `f951`:
```
/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/f951 v.f90
f951: internal compiler error: Segmentation fault
0x1a0e9c4 internal_error(char const*, ...)
        ???:0
0x77d375 gfc_expression_rank(gfc_expr*)
        ???:0
0x7392fc gfc_match_expr(gfc_expr**)
        ???:0
0x6c224b gfc_match_array_ref(gfc_array_ref*, gfc_array_spec*, int, int)
        ???:0
0x7833e8 gfc_match_varspec(gfc_expr*, int, bool, bool)
        ???:0
0x7398e9 gfc_match(char const*, ...)
        ???:0
0x739eed gfc_match_assignment()
        ???:0
0x7938bc gfc_parse_file()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.archlinux.org/> for instructions.
```

This is the gdb backtrace on the segmentation fault:
```
##0  0x000000000077d375 in gfc_expression_rank (e=0x2b61b10) at
/usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc:5643
#1  0x00000000006d6840 in gfc_op_rank_conformable (op2=0x2b61c50,
op1=0x2b61b10) at /usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc:5676
#2  eval_intrinsic (op=INTRINSIC_TIMES, eval=..., op1=0x2b61b10, op2=0x2b61c50)
at /usr/src/debug/gcc/gcc/gcc/fortran/arith.cc:1674
#3  0x000000000074521f in gfc_multiply (op2=<optimized out>, op1=<optimized
out>) at /usr/src/debug/gcc/gcc/gcc/fortran/arith.cc:1926
#4  match_add_operand (result=result@entry=0x7fffffffd550) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:392
#5  0x000000000073884d in match_level_2 (result=result@entry=0x7fffffffd5a0) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:480
#6  0x0000000000738a67 in match_level_3 (result=result@entry=0x7fffffffd608) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:551
#7  0x0000000000738be5 in match_level_4 (result=<synthetic pointer>) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:599
#8  match_and_operand (result=result@entry=0x7fffffffd680) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:693
#9  0x0000000000738e97 in match_or_operand (result=result@entry=0x7fffffffd6e0)
at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:722
#10 0x0000000000738fe7 in match_equiv_operand
(result=result@entry=0x7fffffffd740) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:765
#11 0x0000000000739139 in match_level_5 (result=result@entry=0x7fffffffd798) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:811
#12 0x00000000007392fd in gfc_match_expr (result=0x2bbb460) at
/usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:870
#13 0x00000000006c1aac in match_subscript (ar=ar@entry=0x2bbb338,
init=init@entry=0, match_star=match_star@entry=false) at
/usr/src/debug/gcc/gcc/gcc/fortran/array.cc:94
#14 0x00000000006c224c in gfc_match_array_ref (ar=0x2bbb338, as=<optimized
out>, init=0, corank=0) at /usr/src/debug/gcc/gcc/gcc/fortran/array.cc:211
#15 0x00000000007833e9 in gfc_match_varspec (primary=primary@entry=0x2b612f0,
equiv_flag=equiv_flag@entry=0, sub_flag=sub_flag@entry=false,
ppc_arg=ppc_arg@entry=false)
    at /usr/src/debug/gcc/gcc/gcc/fortran/primary.cc:2166
#16 0x0000000000785043 in match_variable (result=0x7fffffffdb40, equiv_flag=0,
host_flag=<optimized out>) at
/usr/src/debug/gcc/gcc/gcc/fortran/primary.cc:4149
#17 0x00000000007398ea in gfc_match_variable (equiv_flag=0, result=<optimized
out>) at /usr/src/debug/gcc/gcc/gcc/fortran/primary.cc:4164
#18 gfc_match (target=target@entry=0x248a286 " %v =") at
/usr/src/debug/gcc/gcc/gcc/fortran/match.cc:1143
#19 0x0000000000739eee in gfc_match_assignment () at
/usr/src/debug/gcc/gcc/gcc/fortran/match.cc:1321
#20 0x0000000000762a94 in match_word (old_locus=0x7fffffffdba0, subr=0x739eb0
<gfc_match_assignment()>, str=0x0) at
/usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:56
#21 decode_statement () at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:363
#22 0x000000000076f8c2 in next_free () at
/usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:1406
#23 next_statement () at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:1638
#24 0x0000000000775825 in parse_executable (st=st@entry=ST_NONE) at
/usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:5824
#25 0x0000000000773ff9 in parse_associate () at
/usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:5058
#26 parse_executable (st=<optimized out>, st@entry=ST_ASSOCIATE) at
/usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:5878
#27 0x0000000000773a4f in parse_progunit (st=ST_ASSOCIATE,
st@entry=ST_DERIVED_DECL) at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:6294
#28 0x00000000007938bd in gfc_parse_file () at
/usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:6854
#29 0x00000000007ced05 in gfc_be_parse_file () at
/usr/src/debug/gcc/gcc/gcc/fortran/f95-lang.cc:229
#30 0x0000000000d630c1 in compile_file () at
/usr/src/debug/gcc/gcc/gcc/toplev.cc:444
#31 0x00000000006ad7fb in do_compile (no_backend=false) at
/usr/src/debug/gcc/gcc/gcc/toplev.cc:2125
#32 toplev::main (this=<optimized out>, argc=<optimized out>, argv=<optimized
out>) at /usr/src/debug/gcc/gcc/gcc/toplev.cc:2277
#33 0x00000000006ae0e2 in main (argc=<optimized out>, argv=<optimized out>) at
/usr/src/debug/gcc/gcc/gcc/main.cc:39
```

And this is the line whre gdb reports the problem:
```
Program received signal SIGSEGV, Segmentation fault.
0x000000000077d375 in gfc_expression_rank (e=0x2b61b10) at
/usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc:5643
Downloading source file /usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc
5643              rank = ref->u.ar.as->rank;     
```

And finally, here is a Compiler Explorer link reproducing the bug:
https://godbolt.org/z/W3q9ceWxP

Hope is enough information to pin-point the problem.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/111853] f951: Segmentation fault at gfc_expression_rank
  2023-10-17 21:47 [Bug fortran/111853] New: f951: Segmentation fault at gfc_expression_rank canu7 at yahoo dot es
@ 2023-10-18  5:49 ` kargl at gcc dot gnu.org
  2023-12-16 13:27 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-10-18  5:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111853

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Priority|P3                          |P4
   Last reconfirmed|                            |2023-10-18

--- Comment #1 from kargl at gcc dot gnu.org ---
NULL pointer.

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 861f69ac20f..51ff3c7ed21 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -5659,7 +5659,7 @@ gfc_expression_rank (gfc_expr *e)
       if (ref->type != REF_ARRAY)
        continue;

-      if (ref->u.ar.type == AR_FULL)
+      if (ref->u.ar.type == AR_FULL && ref->u.ar.as)
        {
          rank = ref->u.ar.as->rank;
          break;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/111853] f951: Segmentation fault at gfc_expression_rank
  2023-10-17 21:47 [Bug fortran/111853] New: f951: Segmentation fault at gfc_expression_rank canu7 at yahoo dot es
  2023-10-18  5:49 ` [Bug fortran/111853] " kargl at gcc dot gnu.org
@ 2023-12-16 13:27 ` cvs-commit at gcc dot gnu.org
  2024-03-14  9:00 ` fxcoudert at gcc dot gnu.org
  2024-03-15 19:01 ` sgk at troutmask dot apl.washington.edu
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-16 13:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111853

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:5ae6f524f5d4ee2ab79ba797fa4901daf90afb25

commit r14-6620-g5ae6f524f5d4ee2ab79ba797fa4901daf90afb25
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Sat Dec 16 13:26:47 2023 +0000

    Fortran: Fix problems with class array function selectors [PR112834]

    2023-12-16  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/112834
            * match.cc (build_associate_name): Fix whitespace issues.
            (select_type_set_tmp): If the selector is of unknown type, go
            the SELECT TYPE selector to see if this is a function and, if
            the result is available, use its typespec.
            * parse.cc (parse_associate): Again, use the function result if
            the type of the selector result is unknown.
            * trans-stmt.cc (trans_associate_var): The expression has to be
            of type class, for class_target to be true. Convert and fix
            class functions. Pass the fixed expression.

            PR fortran/111853
            * resolve.cc (gfc_expression_rank): Avoid null dereference.

    gcc/testsuite/
            PR fortran/112834
            * gfortran.dg/associate_63.f90 : New test.

            PR fortran/111853
            * gfortran.dg/pr111853.f90 : New test.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/111853] f951: Segmentation fault at gfc_expression_rank
  2023-10-17 21:47 [Bug fortran/111853] New: f951: Segmentation fault at gfc_expression_rank canu7 at yahoo dot es
  2023-10-18  5:49 ` [Bug fortran/111853] " kargl at gcc dot gnu.org
  2023-12-16 13:27 ` cvs-commit at gcc dot gnu.org
@ 2024-03-14  9:00 ` fxcoudert at gcc dot gnu.org
  2024-03-15 19:01 ` sgk at troutmask dot apl.washington.edu
  3 siblings, 0 replies; 5+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2024-03-14  9:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111853

Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu.org

--- Comment #3 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
This seems safe to backport, what do you think?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/111853] f951: Segmentation fault at gfc_expression_rank
  2023-10-17 21:47 [Bug fortran/111853] New: f951: Segmentation fault at gfc_expression_rank canu7 at yahoo dot es
                   ` (2 preceding siblings ...)
  2024-03-14  9:00 ` fxcoudert at gcc dot gnu.org
@ 2024-03-15 19:01 ` sgk at troutmask dot apl.washington.edu
  3 siblings, 0 replies; 5+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2024-03-15 19:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111853

--- Comment #4 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Thu, Mar 14, 2024 at 09:00:22AM +0000, fxcoudert at gcc dot gnu.org wrote:
> 
> --- Comment #3 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
> This seems safe to backport, what do you think?
> 

Paul just landed a big patch dealing with a number
of ASSOCIATE issues.  I have followed all of his
changes.  I'm not opposed to a backport, but may 
be more involved than a simple patch.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-15 19:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-17 21:47 [Bug fortran/111853] New: f951: Segmentation fault at gfc_expression_rank canu7 at yahoo dot es
2023-10-18  5:49 ` [Bug fortran/111853] " kargl at gcc dot gnu.org
2023-12-16 13:27 ` cvs-commit at gcc dot gnu.org
2024-03-14  9:00 ` fxcoudert at gcc dot gnu.org
2024-03-15 19:01 ` sgk at troutmask dot apl.washington.edu

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).