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

Youssef W. Abdallah via flang-commits flang-commits at lists.llvm.org
Sun Oct 18 23:45:03 PDT 2026


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

Fixes: [ #232487 ]

## Summary
* Report the large-columns diagnostic when a positive decimal value for `-ffixed-line-length` exceeds the `int64_t` parsing range of `getAsInteger`.
* Add a regression test for the overflowing value.

## Testing
 `build/bin/llvm-lit -sv flang/test/Driver/fixed-line-length.f90`

>From e6f3bd229e6766ae81b55c7ffc2e779c9ee7249d 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] [flang] Fix fixed line length overflow diagnostic

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

diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index d4c6b44e11477..d7bd442ab7d2e 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -870,7 +870,14 @@ 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 +ve decimals to the large-columns diagnostic below.
+        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})}}
 



More information about the flang-commits mailing list