[flang-commits] [flang] [flang] Fix fixed line length overflow diagnostic (PR #233353)

Youssef W. Abdallah via flang-commits flang-commits at lists.llvm.org
Mon Oct 19 12:50:14 PDT 2026


https://github.com/Wael-06 updated https://github.com/llvm/llvm-project/pull/233353

>From 9a1033631e39fd46f26b2ad817e3073b21f9bcd3 Mon Sep 17 00:00:00 2001
From: Youssef Wael <youssefwael.work at gmail.com>
Date: Mon, 19 Oct 2026 09:38:15 +0300
Subject: [PATCH 1/2] [flang] Fix fixed line length overflow diagnostic

---
 flang/lib/Frontend/CompilerInvocation.cpp | 10 +++++++++-
 flang/test/Driver/fixed-line-length.f90   |  4 ++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index d4c6b44e11477..5c31316662a75 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -870,7 +870,15 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
     if (argValue == "none") {
       columns = 0;
     } else if (argValue.getAsInteger(/*Radix=*/10, columns)) {
-      columns = -1;
+      if (!argValue.empty() &&
+          std::all_of(argValue.begin(), argValue.end(),
+                      [](char c) { return c >= '0' && c <= '9'; })) {
+        // Route oversized positive decimals to the large-columns diagnostic.
+        columns =
+            static_cast<std::int64_t>(std::numeric_limits<int>::max()) + 1;
+      } else {
+        columns = -1;
+      }
     }
     if (columns < 0) {
       diags.Report(clang::diag::err_drv_negative_columns)
diff --git a/flang/test/Driver/fixed-line-length.f90 b/flang/test/Driver/fixed-line-length.f90
index 06d184d5e0109..f2a96b3fb4395 100644
--- a/flang/test/Driver/fixed-line-length.f90
+++ b/flang/test/Driver/fixed-line-length.f90
@@ -7,6 +7,7 @@
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=4294967296 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=OVERFLOWLENGTH
+! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=9223372036854775808 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=INT64OVERFLOW
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=2147483648 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=BOUNDARY
 ! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
 ! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
@@ -19,6 +20,7 @@
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=4294967296 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=OVERFLOWLENGTH
+! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=9223372036854775808 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=INT64OVERFLOW
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=2147483648 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=BOUNDARY
 ! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
 ! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
@@ -42,6 +44,8 @@
 
 ! OVERFLOWLENGTH: invalid value '4294967296' in 'ffixed-line-length=', value must be '2147483647' or smaller
 
+! INT64OVERFLOW: invalid value '9223372036854775808' in 'ffixed-line-length=', value must be '2147483647' or smaller
+
 ! The line should not be trimmed and so 73 characters (including spaces) should be read.
 ! UNLIMITEDLENGTH: program{{(a{59})}}
 

>From 58fb744a0b0ec36e147f59a41165034691461ee1 Mon Sep 17 00:00:00 2001
From: Youssef Wael <youssefwael.work at gmail.com>
Date: Mon, 19 Oct 2026 22:50:01 +0300
Subject: [PATCH 2/2] [flang] Fix fixed line length overflow diagnostic

---
 flang/lib/Frontend/CompilerInvocation.cpp | 8 ++++----
 flang/test/Driver/fixed-line-length.f90   | 4 ++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 5c31316662a75..3e8e806c26d9d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -29,6 +29,8 @@
 #include "clang/Options/OptionUtils.h"
 #include "clang/Options/Options.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Frontend/Debug/Options.h"
@@ -870,12 +872,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
     if (argValue == "none") {
       columns = 0;
     } else if (argValue.getAsInteger(/*Radix=*/10, columns)) {
-      if (!argValue.empty() &&
-          std::all_of(argValue.begin(), argValue.end(),
-                      [](char c) { return c >= '0' && c <= '9'; })) {
+      if (!argValue.empty() && llvm::all_of(argValue, llvm::isDigit)) {
         // Route oversized positive decimals to the large-columns diagnostic.
         columns =
-            static_cast<std::int64_t>(std::numeric_limits<int>::max()) + 1;
+            static_cast<std::int64_t>(std::numeric_limits<int>::max());
       } else {
         columns = -1;
       }
diff --git a/flang/test/Driver/fixed-line-length.f90 b/flang/test/Driver/fixed-line-length.f90
index f2a96b3fb4395..0f873531bb872 100644
--- a/flang/test/Driver/fixed-line-length.f90
+++ b/flang/test/Driver/fixed-line-length.f90
@@ -8,6 +8,7 @@
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=4294967296 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=OVERFLOWLENGTH
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=9223372036854775808 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=INT64OVERFLOW
+! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=-99999999999999999999 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=NEGATIVEOVERFLOW
 ! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=2147483648 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=BOUNDARY
 ! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
 ! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
@@ -21,6 +22,7 @@
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=4294967296 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=OVERFLOWLENGTH
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=9223372036854775808 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=INT64OVERFLOW
+! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=-99999999999999999999 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=NEGATIVEOVERFLOW
 ! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=2147483648 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=BOUNDARY
 ! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
 ! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
@@ -46,6 +48,8 @@
 
 ! INT64OVERFLOW: invalid value '9223372036854775808' in 'ffixed-line-length=', value must be '2147483647' or smaller
 
+! NEGATIVEOVERFLOW: invalid value '-99999999999999999999' in 'ffixed-line-length=', value must be 'none' or a positive integer
+
 ! The line should not be trimmed and so 73 characters (including spaces) should be read.
 ! UNLIMITEDLENGTH: program{{(a{59})}}
 



More information about the flang-commits mailing list