diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md --- a/flang/docs/Extensions.md +++ b/flang/docs/Extensions.md @@ -108,6 +108,7 @@ * Quad precision REAL literals with `Q` * `X` prefix/suffix as synonym for `Z` on hexadecimal literals * `B`, `O`, `Z`, and `X` accepted as suffixes as well as prefixes +* Support for using bare `L` in FORMAT statement * Triplets allowed in array constructors * `%LOC`, `%VAL`, and `%REF` * Leading comma allowed before I/O item list diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp --- a/flang/runtime/edit-output.cpp +++ b/flang/runtime/edit-output.cpp @@ -139,6 +139,8 @@ case 'Z': return EditBOZOutput<4>( io, edit, reinterpret_cast(&n), KIND); + case 'L': + return EditLogicalOutput(io, edit, *reinterpret_cast(&n)); case 'A': // legacy extension return EditCharacterOutput( io, edit, reinterpret_cast(&n), sizeof n); @@ -590,6 +592,8 @@ common::BitsForBinaryPrecision(common::PrecisionOfRealKind(KIND)) >> 3); case 'G': return Edit(EditForGOutput(edit)); + case 'L': + return EditLogicalOutput(io_, edit, *reinterpret_cast(&x_)); case 'A': // legacy extension return EditCharacterOutput( io_, edit, reinterpret_cast(&x_), sizeof x_); @@ -713,6 +717,8 @@ case 'Z': return EditBOZOutput<4>(io, edit, reinterpret_cast(x), sizeof(CHAR) * length); + case 'L': + return EditLogicalOutput(io, edit, *reinterpret_cast(x)); default: io.GetIoErrorHandler().SignalError(IostatErrorInFormat, "Data edit descriptor '%c' may not be used with a CHARACTER data item", diff --git a/flang/runtime/format-implementation.h b/flang/runtime/format-implementation.h --- a/flang/runtime/format-implementation.h +++ b/flang/runtime/format-implementation.h @@ -479,7 +479,8 @@ } } } - if (edit.descriptor == 'A') { // width is optional for A[w] + if (edit.descriptor == 'A' || edit.descriptor == 'L') { + // width is optional for A[w] or L[w] auto ch{PeekNext()}; if (ch >= '0' && ch <= '9') { edit.width = GetIntField(context); diff --git a/flang/test/Driver/print-logical.f90 b/flang/test/Driver/print-logical.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/print-logical.f90 @@ -0,0 +1,23 @@ +! RUN: rm -f %t.out %t.txt +! RUN: %flang -flang-experimental-exec %s -o %t.out +! RUN: %t.out > %t.txt +! RUN: cat %t.txt | FileCheck %s + +program L + implicit none + character(len=15) :: fmt1 = "(L, L1, I3, L2)" + character(len=15) :: fmt2 = "(L1, L, I3, L2)" + character(len=20) :: fmt3 = "(I2, L2, A4, L2, L2)" + character(len=20) :: fmt4 = "(L1, F4.1, L2, L2)" + +! CHECK: TF 6 T + print fmt1, .true., .false., 6, 22 +! CHECK: FT 0 F + print fmt2, .false., .true., 0, 0 + +! CHECK: -2 T ABC T F + print fmt3, -2, -3, "ABC", "DE", 0.0 +! CHECK: T 2.3 F F + print fmt4, -3, 2.3, "", 0.0 + +end program L