llvm/llvm-project
flang-rt
flang-rt/ is the runtime support library for code compiled by Flang. It implements the bits of Fortran semantics that can't be reduced to inline machine code: I/O, allocatable and pointer descriptor management, intrinsic procedures with non-trivial implementations, OpenMP runtime entry points, and similar functionality.
Purpose
A Fortran program lowered through Flang's pipeline ends up calling into flang-rt for any operation whose implementation is large enough or sufficiently runtime-state-dependent that inlining it would bloat every callsite. Examples include READ/WRITE against formatted/unformatted units, ALLOCATE/DEALLOCATE with shape and bounds tracking, derived-type assignment, transformational intrinsics like RESHAPE and MATMUL, and the runtime descriptors that back assumed-shape arrays.
History
The Flang runtime originally lived inside flang/ as flang/runtime/. It was carved out into its own top-level subproject (flang-rt/) so it could be built like other LLVM runtime libraries — through LLVM_ENABLE_RUNTIMES rather than LLVM_ENABLE_PROJECTS, with the option of cross-compiling for offload targets. See flang-rt/README.md for the rationale and the migration plan.
Directory layout
flang-rt/
├── include/flang-rt/ # Public headers (descriptor types, runtime-side interface)
├── lib/ # Implementation — IO, allocations, intrinsics, exceptions, ...
├── unittests/
├── test/ # lit regression tests (driven against built artifacts)
├── cmake/
├── docs/
├── examples/
└── README.mdWhat it implements
A non-exhaustive list of what flang-rt provides at runtime:
- Descriptors — the C structures that back allocatable, pointer, and assumed-shape arrays. The same shape descriptors are exposed at the C /
BIND(C)interop boundary. - I/O —
READ,WRITE,OPEN,CLOSE,INQUIRE, list-directed/formatted/unformatted/namelist transfers, recursive I/O, asynchronous I/O. - Memory and lifetime —
ALLOCATE,DEALLOCATE,MOVE_ALLOC, automatic cleanup at scope exit, finalization of derived types. - Intrinsics that don't inline —
RESHAPE,TRANSFER,MATMUL,DOT_PRODUCT,SUM,MINVAL/MAXVAL,PACK/UNPACK,SPREAD,EOSHIFT/CSHIFT, character-handling intrinsics. - Exception flags / IEEE features — environment for IEEE-arithmetic state.
- Stop / error handling —
STOP,ERROR STOP, image control statements.
Integration points
- Flang lowers calls into flang-rt via well-defined symbol names (
_FortranA*,_FortranAio*, ...). The naming convention is documented insideflang-rt/include/flang-rt/andflang/include/flang/Runtime/. - MLIR / FIR lowering inserts the runtime calls at lowering time; FIR ops have direct counterparts that emit the right runtime entry points.
- OpenMP / Offload runtimes (
openmp,offload) cooperate with flang-rt for offloaded Fortran code.
Entry points for modification
- Adding a runtime intrinsic: add the C++ implementation under
flang-rt/lib/, declare the symbol in the corresponding header underflang-rt/include/flang-rt/(and the matching declaration on the compiler side underflang/include/flang/Runtime/), and emit calls fromflang/lib/Lower/. - Adding an I/O capability: edit the relevant
flang-rt/lib/IO/files.
Reference
flang-rt/README.md— full design and migration notes- Flang runtime documentation
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.
Previous
flang
Next
libc