Skip to content

Account for Fortran assumed shape#2821

Draft
joewallwork wants to merge 3 commits into
mainfrom
2820_fortran-assumed-shape
Draft

Account for Fortran assumed shape#2821
joewallwork wants to merge 3 commits into
mainfrom
2820_fortran-assumed-shape

Conversation

@joewallwork
Copy link
Copy Markdown
Collaborator

@joewallwork joewallwork commented May 11, 2026

Closes #2820.

As documented in the issue, I wasn't able to build the allocatableArraySimple example locally. It seemed that Enzyme didn't fully account for assumed shape arrays in Fortran. The small patch in this PR addresses this and I can confirm I can now forward and reverse mode differentiate through things like

  subroutine normalise(x, y)
    real, dimension(:), intent(in) :: x
    real, dimension(:), intent(out) :: y
    y(:) = x / sum(x)
  end subroutine normalise

which is really nice.

If I understand correctly, the error message I was hitting was slightly misleading so I propose an alternative phrasing.

@joewallwork joewallwork self-assigned this May 11, 2026
@joewallwork joewallwork added enhancement New feature or request fortran Related to Enzyme's Fortran bindings labels May 11, 2026
@joewallwork joewallwork marked this pull request as ready for review May 11, 2026 11:20
@joewallwork joewallwork force-pushed the 2820_fortran-assumed-shape branch from 7cf1051 to 644ef32 Compare May 11, 2026 13:20
@joewallwork joewallwork changed the title Account for Fortran assumed shape in reverse mode Account for Fortran assumed shape May 11, 2026
@joewallwork
Copy link
Copy Markdown
Collaborator Author

This all works well on it's own. However, I've just discovered that it doesn't work in conjunction with #2809. I tested this branch merged with that one on cases with assumed shape arrays and they compile but produce segfaults. This branch also produces a warning like

warning: binary operator is integer and assumed constant:   %19 = mul nsw i64 %11, %15

for each assumed shape array encountered, which isn't ideal. For a full fix, we should address #2822.

@joewallwork joewallwork marked this pull request as draft May 11, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fortran Related to Enzyme's Fortran bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error applying Enzyme to alloctableArraySimple Fortran example

1 participant