Skip to content

Mark inactive Fortran calls - #3194

Draft
joewallwork wants to merge 2 commits into
mainfrom
fortran-inactive
Draft

joewallwork wants to merge 2 commits into
mainfrom
fortran-inactive

Conversation

@joewallwork

Copy link
Copy Markdown
Collaborator

Refinement of #3168

This PR marks a few Fortran-related things as inactive in the activity analysis.

vchuravy and others added 2 commits September 8, 2026 15:38
KnownInactiveFunctionsStartingWith already lists "f90io", classic flang's I/O
runtime. LLVM flang names the same thing _FortranAio*, which was not covered,
so differentiating any Fortran routine that prints -- DVODE's xerrwd, for
instance -- failed with "No forward mode derivative found".

Also add _FortranAClassIs and _FortranATrim, a type query and character
handling; neither moves floating point data.

_FortranAAssign is deliberately not included. It copies data which may include
reals, so declaring it inactive would silently drop a derivative; it needs a
rule that assigns the shadow too.

On a whole-program Fortran module differentiating DVODE, with loose types, this
takes the error count from 17 to 1, the remainder being that _FortranAAssign.
check-enzyme and check-typeanalysis are unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@joewallwork joewallwork self-assigned this Sep 8, 2026
@joewallwork joewallwork added the fortran Related to Enzyme's Fortran bindings label Sep 8, 2026
@vchuravy

vchuravy commented Sep 9, 2026

Copy link
Copy Markdown
Member

Some Claude review:

  • The _FortranAio prefix also matches flang's READ entry points (_FortranAioInputReal32/64, InputComplex*, InputDescriptor, InputUnformattedBlock), which overwrite user floating-point memory, so marking them inactive leaves the destination shadow un-zeroed and turns a loud failure into a silently wrong derivative.

  • Adding these names to the inactive lists is not sufficient for reverse mode, because the constant-fallback path calls EnzymeLogic::CreateNoFree on the declaration-only callee, which hard-errors since no _FortranA* name is in its NoFrees list.

  • The new comment's justification that "the comparison above is unsigned, so an entry at the any-offset index -1 is skipped" holds only for a 64-bit size_t, making the block's behavior platform-dependent and documenting an accident as intent.

This branch has not been deployed

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

Labels

fortran Related to Enzyme's Fortran bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants