[flang-commits] [flang] [llvm] [flang][flang-rt] Implement F202X leading-zero control edit descriptors LZ, LZS, and LZP for formatted output (F, E, D, and G editing) (PR #183500)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Thu Mar 19 15:52:37 PDT 2026


================
@@ -688,6 +688,29 @@ bool IODEF(SetSign)(Cookie cookie, const char *keyword, std::size_t length) {
   }
 }
 
+bool IODEF(SetLeadingZero)(
----------------
eugeneepshteyn wrote:

There's a comment in llvm-project/flang/include/flang/Optimizer/Transforms/RuntimeFunctions.inc:
```
// Fortran runtime functions that SetRuntimeCallAttributesPass recognizes.
// WARNING: if you add a function entry here, you must make sure
// that the attribute computation callbacks that end up being
// used are correct for this function. If needed, add
// specializations for the types that provide attribute
// computation callbacks in SetRuntimeCallAttributesPass.
```
Perhaps `SetLeadingZero` should be added to that list as well?

I asked AI about it and it came up with the following:

The new `SetLeadingZero` runtime function is not added to `RuntimeFunctions.inc` (alongside `SetSign`, `SetRound`, `SetPad`, etc.). This table is consumed by `SetRuntimeCallAttributesPass` to attach `{fir.io, fir.runtime}` memory-effect attributes to known I/O calls. Missing entries mean:

1. Calls to `_FortranAioSetLeadingZero` in generated IR won't receive the `{fir.llvm_memory = ..., llvm.nocallback, llvm.nosync}` attributes that all other `Set*` I/O functions get. This is a quality-of-implementation gap — it causes the optimizer to be overly conservative around those calls.
2. Two derived test files must also be updated:
   - `flang/test/Transforms/verify-known-runtime-functions.fir` — auto-generated CHECK-NEXT list of all known runtime function signatures. Updating `RuntimeFunctions.inc` and re-running the generator script will produce the correct entry.
   - `flang/test/Transforms/set-runtime-call-attributes.fir` — functional test for the attributes pass; a new test case for `_FortranAioSetLeadingZero` should be added following the pattern of the existing `@test__FortranAioSetSign` and `@test__FortranAioSetRound` cases.

**Fix:** Add `KNOWN_IO_FUNC(SetLeadingZero),` to `RuntimeFunctions.inc` (alphabetically between `SetForm`/`SetFile` and `SetPad`), then re-run `generate-checks-for-runtime-funcs.py` to update `verify-known-runtime-functions.fir`, and add a corresponding test case in `set-runtime-call-attributes.fir`.

https://github.com/llvm/llvm-project/pull/183500


More information about the flang-commits mailing list