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 @@ -484,7 +484,8 @@ if (ch >= '0' && ch <= '9') { edit.width = GetIntField(context); } - } else if (edit.descriptor != DataEdit::DefinedDerivedType) { + } else if (edit.descriptor != DataEdit::DefinedDerivedType && + edit.descriptor != 'L') { edit.width = GetIntField(context); } if constexpr (std::is_base_of_v) { 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,53 @@ +! 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 +! CHECK: T + print "(L)", .true. +! CHECK-NEXT: T + print "(L1)", .true. + +! CHECK-NEXT: F + print "(L)", .false. +! CHECK-NEXT: F + print "(L1)", .false. + +! CHECK-NEXT: T + print "(L)", 22 +! CHECK-NEXT: T + print "(L1)", 22 + +! CHECK-NEXT: F + print "(L)", 0 +! CHECK-NEXT: F + print "(L1)", 0 + +! CHECK-NEXT: T + print "(L)", -2 +! CHECK-NEXT: T + print "(L1)", -2 + +! CHECK-NEXT: T + print "(L)", "ABC" +! CHECK-NEXT: T + print "(L1)", "ABC" + +! CHECK-NEXT: F + print "(L)", "" +! CHECK-NEXT: F + print "(L1)", "" + +! CHECK-NEXT: T + print "(L)", 2.3 +! CHECK-NEXT: T + print "(L1)", 2.3 + +! CHECK-NEXT: F + print "(L)", 0.0 +! CHECK-NEXT: F + print "(L1)", 0.0 + +end program L