[flang-commits] [flang] [llvm] [flang] [flang-rt] Implement AT edit descriptor for Fortran 202X with appropriate handling and tests (PR #189157)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Fri Apr 10 12:52:18 PDT 2026


================
@@ -921,6 +921,13 @@ template <typename CHAR>
 RT_API_ATTRS bool EditCharacterOutput(IoStatementState &io,
     const DataEdit &edit, const CHAR *x, std::size_t length) {
   int len{static_cast<int>(length)};
+  if (edit.descriptor == 'A' && edit.variation == 'T') {
+    // AT edit descriptor: trim trailing blanks (F2023 TRIM semantics)
+    while (len > 0 && x[len - 1] == static_cast<CHAR>(' ')) {
+      --len;
+    }
+    return EmitEncoded(io, x, len);
+  }
----------------
eugeneepshteyn wrote:

AI code reviewer had concerns here. Could you please check that this works correctly with the following test?
```
program test_at_recl
  character(20) :: str
  str = 'hello world         '   ! 20 chars, trailing blanks trimmed by AT to 11

  ! Direct-access formatted file with record length 5.
  ! AT will attempt to emit 11 characters into a 5-character record.
  open(10, file='at_recl_test.dat', form='formatted', access='direct', recl=5)
  write(10, '(AT)', rec=1) str   ! Overflows: EmitEncoded called with len=11, recl=5
  close(10)
end program
```

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


More information about the flang-commits mailing list