Bug 125529 - ICE (segfault) in DO CONCURRENT with DEFAULT(NONE) and ASSOCIATE
Summary: ICE (segfault) in DO CONCURRENT with DEFAULT(NONE) and ASSOCIATE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 16.0
: P3 normal
Target Milestone: ---
Assignee: Jerry DeLisle
URL:
Keywords:
Depends on:
Blocks: 125515
  Show dependency tree / graph
 
Reported: 2026-05-31 19:54 UTC by Jerry DeLisle
Modified: 2026-06-21 02:44 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2026-06-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerry DeLisle 2026-05-31 19:54:52 UTC
gfortran segfaults when a DO CONCURRENT construct uses inline type-spec iterators and DEFAULT(NONE) and the body contains an ASSOCIATE construct.

  subroutine test (a, b)
    implicit none
    integer, intent(in)  :: a(10,10)
    integer, intent(out) :: b(10,10)
    do concurrent (integer :: i = 1:10, j = 1:10) &
        default(none) shared(a, b)
      associate (tmp => a(i,j))
        b(i,j) = tmp + 1
      end associate
    end do
  end subroutine

  $ gfortran -std=f2018 -c do_concurrent_assoc_default_none.f90

  gfortran segfaults.  The code should compile cleanly.
Comment 1 GCC Commits 2026-06-04 23:24:21 UTC
The master branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>:

https://gcc.gnu.org/g:2851a6b21c89d80b81f9ce06cdfb943a172eca42

commit r17-1358-g2851a6b21c89d80b81f9ce06cdfb943a172eca42
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Wed May 27 21:00:19 2026 -0700

    fortran: ICE in DO CONCURRENT with DEFAULT(NONE) inside ASSOCIATE
    
    Two bugs in check_default_none_expr caused a segfault when a DO CONCURRENT
    with inline type-spec iterators (e.g. "integer :: i = 1:10") contained an
    ASSOCIATE construct.
    
    Bug 1: sym->ns->code was used to locate the ext.concur.forall_iterator
    list.  When a symbol's namespace is an ASSOCIATE body, sym->ns->code is an
    EXEC_BLOCK node, not the DO CONCURRENT node; reading ext.concur from it
    interprets the wrong union member and yields a garbage pointer.  Fix: use
    d->code instead, the DO CONCURRENT gfc_code node passed through the walker's
    data parameter, which is always the correct node.
    
    Bug 2: inline type-spec iterators are shadow iterators, stored internally
    with a leading underscore prepended to the name.  The comparison of the
    iterator's symtree name against the user-visible sym->name must skip that
    underscore by advancing iter_name one character when iter->shadow is set.
    
    PR fortran/125529
    
    Assisted by: Claude Sonnet 4.6
    
    gcc/fortran/ChangeLog:
    
            PR fortran/125529
            * resolve.cc (check_default_none_expr): Use d->code instead of
            sym->ns->code to locate the DO CONCURRENT forall_iterator list,
            avoiding a wrong-union-member read when the symbol's namespace is
            an ASSOCIATE body.  Skip leading underscore when comparing iterator
            names for shadow iterators.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/125529
            * gfortran.dg/do_concurrent_assoc_default_none.f90: New test.
    
    (cherry picked from commit afe36f5576f07a5650ed8e2d9ade58d2e7e27021)
Comment 2 GCC Commits 2026-06-15 16:31:05 UTC
The releases/gcc-16 branch has been updated by Jerry DeLisle <jvdelisle@gcc.gnu.org>:

https://gcc.gnu.org/g:37724f8a90f0b9ebc5d8883ea0af71edaef2cc35

commit r16-9106-g37724f8a90f0b9ebc5d8883ea0af71edaef2cc35
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Wed May 27 21:00:19 2026 -0700

    fortran: ICE in DO CONCURRENT with DEFAULT(NONE) inside ASSOCIATE
    
    Two bugs in check_default_none_expr caused a segfault when a DO CONCURRENT
    with inline type-spec iterators (e.g. "integer :: i = 1:10") contained an
    ASSOCIATE construct.
    
    Bug 1: sym->ns->code was used to locate the ext.concur.forall_iterator
    list.  When a symbol's namespace is an ASSOCIATE body, sym->ns->code is an
    EXEC_BLOCK node, not the DO CONCURRENT node; reading ext.concur from it
    interprets the wrong union member and yields a garbage pointer.  Fix: use
    d->code instead, the DO CONCURRENT gfc_code node passed through the walker's
    data parameter, which is always the correct node.
    
    Bug 2: inline type-spec iterators are shadow iterators, stored internally
    with a leading underscore prepended to the name.  The comparison of the
    iterator's symtree name against the user-visible sym->name must skip that
    underscore by advancing iter_name one character when iter->shadow is set.
    
    Assisted by: Claude Sonnet 4.6
    
            PR fortran/125529
    
    gcc/fortran/ChangeLog:
    
            * resolve.cc (check_default_none_expr): Use d->code instead of
            sym->ns->code to locate the DO CONCURRENT forall_iterator list,
            avoiding a wrong-union-member read when the symbol's namespace is
            an ASSOCIATE body.  Skip leading underscore when comparing iterator
            names for shadow iterators.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/do_concurrent_assoc_default_none.f90: New test.
    
    (cherry picked from commit 7fd7fdfa4c228089277ddfbadda55dc8c3077726)
Comment 3 Jerry DeLisle 2026-06-21 02:44:32 UTC
Closing before I lose track.