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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-parser

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/183196.diff


2 Files Affected:

- (modified) flang/lib/Parser/unparse.cpp (+1-3) 
- (added) flang/test/Parser/bug2280.f90 (+6) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list