Skip to content

lfortran ICE on accessing parent component in a dummy argument #10978

Closed

Description

@rouson

I just pushed a commit to Formal to work around an lfortran internal compiler error (ICE) .  As shown below, the workaround is trivial so this issue not important to me. I'm just reporting it so you're aware.

% git clone git@github.com:berkeleylab/formal
% cd formal
% git checkout workaround-lfortran-ice  
% git diff HEAD~1
diff --git a/src/formal/dyad_1D_s.F90 b/src/formal/dyad_1D_s.F90
index 260ef3b..50c3ed5 100644
--- a/src/formal/dyad_1D_s.F90
+++ b/src/formal/dyad_1D_s.F90
@@ -18,7 +18,7 @@ submodule(tensors_1D_m) dyad_1D_s
 contains
 
   module procedure dyad_over_integer
-    ratio%tensor_1D_t = tensor_1D_t(self%tensor_1D_t%values_/numerator, self%x_min_, self%x_max_, self%cells_, order = self%order_)
+    ratio%tensor_1D_t = tensor_1D_t(self%values_/numerator, self%x_min_, self%x_max_, self%cells_, order = self%order_)
     ratio%divergence_operator_1D_ = self%divergence_operator_1D_
   end procedure

Activity

  1. rouson commented on Apr 6, 2026

    @rouson
    ContributorAuthor

    Correction: although the above workaround resolves this issue in the checked configurations below, it fails on the unchecked one.

    Is this a regression or is it possible that the container has an lfortran version older than 0.6.1?

  2. certik commented on Sep 27, 2026

    @certik
    Contributor

    This is fixed on current main (and in releases since 0.64.0) by commit 71e4f6d "Fix parent-type-name component access crash" (PR #12116, regression test integration_tests/derived_types_149.f90).

    Here is a small example with the pattern from the issue: accessing a component through the parent-type name (self%parent_t%values_) of a class() dummy inside a submodule procedure.

    module m
      implicit none
      type :: parent_t
        double precision, allocatable :: values_(:)
        integer :: order_ = 0
      end type
      type, extends(parent_t) :: child_t
        integer :: extra_ = 0
      end type
      interface
        pure module function child_over_integer(self, n) result(ratio)
          class(child_t), intent(in) :: self
          integer, intent(in) :: n
          type(child_t) :: ratio
        end function
      end interface
    end module
    
    submodule(m) m_s
      implicit none
    contains
      module procedure child_over_integer
        ratio%parent_t = parent_t(self%parent_t%values_/n, order_=self%order_)
        ratio%extra_ = self%extra_
      end procedure
    end submodule
    
    program ex10978
      use m
      implicit none
      type(child_t) :: c, r
      c%parent_t = parent_t([2d0, 4d0, 6d0], order_=2)
      c%extra_ = 7
      r = child_over_integer(c, 2)
      print *, r%values_, r%order_, r%extra_
      if (any(r%values_ /= [1d0, 2d0, 3d0])) error stop
      if (r%order_ /= 2 .or. r%extra_ /= 7) error stop
    end program

    With LFortran 0.63.0 the compiler segfaults:

    $ lfortran ex10978.f90
    Segmentation fault
    

    With current main (0.66.0-445-g611fbfe8d):

    $ lfortran ex10978.f90
    1.0000000000000000 2.0000000000000000 3.0000000000000000 2 7
    

    This matches gfortran.

    I also checked Formal itself with current main, both before the workaround (420c46f) and at the workaround commit (7bb94ce). Both build, and fpm test --compiler lfortran --flag "--cpp --realloc-lhs-arrays --separate-compilation" passes. Current Formal main passes as well.

    About the earlier comment that the workaround still failed in the LFortran container: I could not reproduce that with 0.61, 0.63 or current main. The container image was most likely older than the fix. If you still see a failure with a current ghcr.io/lfortran/lfortran:latest, please post the full lfortran --version, the exact command line, and the error output, and we'll reopen.


    Generated by Claude Code

  3. certik commented on Sep 27, 2026

    @certik
    Contributor

    It looks like this is now fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions