[flang-commits] [flang] a95de36 - [flang] Reject oversized -ffixed-line-length values (#229972)
via flang-commits
flang-commits at lists.llvm.org
Thu Oct 15 01:55:07 PDT 2026
Author: Popie
Date: 2026-10-15T09:55:01+01:00
New Revision: a95de3678c471175336eacda36a1a595a0c04b0b
URL: https://github.com/llvm/llvm-project/commit/a95de3678c471175336eacda36a1a595a0c04b0b
DIFF: https://github.com/llvm/llvm-project/commit/a95de3678c471175336eacda36a1a595a0c04b0b.diff
LOG: [flang] Reject oversized -ffixed-line-length values (#229972)
Fixes #227460
## Summary
Reject values of -ffixed-line-length that exceed
std::numeric_limits<int>::max().
The option value is parsed as a 64-bit integer but stored as an
int. Values exceeding the maximum representable int value could
therefore be narrowed without proper validation.
Add a diagnostic for oversized values and regression tests covering
the integer boundary for both flang and flang_fc1.
Tests:
- flang/test/Driver/fixed-line-length.f90
Added:
Modified:
clang/include/clang/Basic/DiagnosticDriverKinds.td
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/fixed-line-length.f90
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index ce0f688108cc7f..b5b1ac744b49de 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -443,6 +443,8 @@ def err_drv_negative_columns : Error<
"invalid value '%1' in '%0', value must be 'none' or a positive integer">;
def err_drv_small_columns : Error<
"invalid value '%1' in '%0', value must be '%2' or greater">;
+def err_drv_large_columns : Error<
+ "invalid value '%1' in '%0', value must be '%2' or smaller">;
def warn_drv_fraw_string_literals_in_cxx11 : Warning<
"ignoring '-f%select{no-|}0raw-string-literals', which is only valid for C and C++ standards before C++11">,
InGroup<UnusedCommandLineArgument>;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 46ccebe3b030b3..d4c6b44e114772 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -46,6 +46,7 @@
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <cstdlib>
+#include <limits>
#include <memory>
#include <optional>
@@ -879,6 +880,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
} else if (columns < 7) {
diags.Report(clang::diag::err_drv_small_columns)
<< arg->getOption().getName() << arg->getValue() << "7";
+ } else if (columns > std::numeric_limits<int>::max()) {
+ diags.Report(clang::diag::err_drv_large_columns)
+ << arg->getOption().getName() << arg->getValue()
+ << std::numeric_limits<int>::max();
} else {
opts.fixedFormColumns = columns;
}
diff --git a/flang/test/Driver/fixed-line-length.f90 b/flang/test/Driver/fixed-line-length.f90
index 879b7de7089e89..06d184d5e01092 100644
--- a/flang/test/Driver/fixed-line-length.f90
+++ b/flang/test/Driver/fixed-line-length.f90
@@ -6,6 +6,8 @@
! RUN: %flang -E -Xflang -fno-reformat %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
! 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=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
! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=LENGTH13
@@ -16,9 +18,12 @@
! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
! 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=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
! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=2147483647 %S/Inputs/fixed-line-length-test.f 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
!-------------------------------------
! COMMAND ALIAS -ffixed-line-length-n
@@ -29,10 +34,14 @@
! The line should be trimmed to 72 characters when reading based on the default value of fixed line length.
! DEFAULTLENGTH: program{{(a{58})}}
+! BOUNDARY: invalid value '2147483648' in 'ffixed-line-length=', value must be '2147483647' or smaller
+
! NEGATIVELENGTH: invalid value '-2' in 'ffixed-line-length=', value must be 'none' or a positive integer
! INVALIDLENGTH: invalid value '3' in 'ffixed-line-length=', value must be '7' or greater
+! OVERFLOWLENGTH: invalid value '4294967296' 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