[flang-commits] [flang] [flang] Don't unparse 1X or X format as X (PR #183196)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Feb 24 15:00:06 PST 2026


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/183196

The unparsing code emits a bare X control edit descriptor when its repetition count is 1, since a bare X control edit descriptor defaults to 1X. But it's not conforming usage, so it might cause a warning if unparsed code is recompiled with -pedantic.  So don't do that.

>From f2f49bf118123186b6823c57773fac392674be6e Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 24 Feb 2026 14:56:45 -0800
Subject: [PATCH] [flang] Don't unparse 1X or X format as X

The unparsing code emits a bare X control edit descriptor when its
repetition count is 1, since a bare X control edit descriptor defaults to 1X.
But it's not conforming usage, so it might cause a warning if unparsed code
is recompiled with -pedantic.  So don't do that.
---
 flang/lib/Parser/unparse.cpp  | 4 +---
 flang/test/Parser/bug2280.f90 | 6 ++++++
 2 files changed, 7 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Parser/bug2280.f90

diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 3d8ea9f703b2f..9d01bb74d70d3 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -1514,9 +1514,7 @@ class UnparseVisitor {
       Walk(x.count);
       break;
     case format::ControlEditDesc::Kind::X:
-      if (x.count != 1) {
-        Walk(x.count);
-      }
+      Walk(x.count);
       Word("X");
       break;
     case format::ControlEditDesc::Kind::Slash:
diff --git a/flang/test/Parser/bug2280.f90 b/flang/test/Parser/bug2280.f90
new file mode 100644
index 0000000000000..d24b26ddeb0d8
--- /dev/null
+++ b/flang/test/Parser/bug2280.f90
@@ -0,0 +1,6 @@
+!RUN: %flang -fc1 -fdebug-unparse %s | FileCheck %s
+!CHECK: 1 FORMAT(1X)
+1 format(1x)
+!CHECK: 2 FORMAT(1X)
+2 format(x)
+end



More information about the flang-commits mailing list