[flang-commits] [clang] [flang] [Flang] Adding -ffree-line-length-<value> flag (PR #192941)
Jean-Didier PAILLEUX via flang-commits
flang-commits at lists.llvm.org
Thu Apr 23 05:30:05 PDT 2026
https://github.com/JDPailleux updated https://github.com/llvm/llvm-project/pull/192941
>From f4506ae9a304e1113f96ff639685bebfa1184450 Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Fri, 17 Apr 2026 14:55:20 +0200
Subject: [PATCH 1/7] [Flang] Adding -ffree-line-length-<value> flag
---
clang/include/clang/Options/Options.td | 6 ++-
clang/lib/Driver/ToolChains/Flang.cpp | 1 +
.../include/flang/Frontend/FrontendOptions.h | 8 +++-
flang/include/flang/Parser/options.h | 1 +
flang/lib/Frontend/CompilerInvocation.cpp | 12 ++++--
flang/lib/Parser/parsing.cpp | 1 +
flang/lib/Parser/prescan.cpp | 3 ++
flang/lib/Parser/prescan.h | 5 +++
.../Driver/Inputs/free-line-length-test.f90 | 4 ++
flang/test/Driver/ffree-line-length.f90 | 38 +++++++++++++++++++
10 files changed, 72 insertions(+), 7 deletions(-)
create mode 100644 flang/test/Driver/Inputs/free-line-length-test.f90
create mode 100644 flang/test/Driver/ffree-line-length.f90
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 5673fb0c47d5b..da54596ede209 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7454,7 +7454,6 @@ def static_libgfortran : Flag<["-"], "static-libgfortran">, Group<gfortran_Group
def fblas_matmul_limit_EQ : Joined<["-"], "fblas-matmul-limit=">, Group<gfortran_Group>;
def fcheck_EQ : Joined<["-"], "fcheck=">, Group<gfortran_Group>;
def ffpe_trap_EQ : Joined<["-"], "ffpe-trap=">, Group<gfortran_Group>;
-def ffree_line_length_VALUE : Joined<["-"], "ffree-line-length-">, Group<gfortran_Group>;
def finit_character_EQ : Joined<["-"], "finit-character=">, Group<gfortran_Group>;
def finit_integer_EQ : Joined<["-"], "finit-integer=">, Group<gfortran_Group>;
def finit_logical_EQ : Joined<["-"], "finit-logical=">, Group<gfortran_Group>;
@@ -7613,6 +7612,11 @@ def ffixed_line_length_EQ : Joined<["-"], "ffixed-line-length=">, Group<f_Group>
DocBrief<[{Set column after which characters are ignored in typical fixed-form lines in the source
file}]>;
def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, Group<f_Group>, Alias<ffixed_line_length_EQ>;
+def ffree_line_length_EQ : Joined<["-"], "ffree-line-length=">, Group<f_Group>,
+ HelpText<"Use <value> as character line width in free mode">,
+ DocBrief<[{Set column after which characters are ignored in typical free-form lines in the source
+file}]>;
+def ffree_line_length_VALUE : Joined<["-"], "ffree-line-length-">, Group<f_Group>, Alias<ffree_line_length_EQ>;
def fconvert_EQ : Joined<["-"], "fconvert=">, Group<f_Group>,
HelpText<"Set endian conversion of data for unformatted files">;
def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group<f_Group>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index ce503b74295e4..41ad4288ccc6f 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -40,6 +40,7 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
Args.addAllArgs(CmdArgs, {options::OPT_ffixed_form,
options::OPT_ffree_form,
options::OPT_ffixed_line_length_EQ,
+ options::OPT_ffree_line_length_EQ,
options::OPT_fopenacc,
options::OPT_finput_charset_EQ,
options::OPT_fimplicit_none,
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 0bd2e621813ca..25683fc25f4b2 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -145,10 +145,10 @@ enum class FortranForm {
/// The user has not specified a form. Base the form off the file extension.
Unknown,
- /// -ffree-form
+ /// -ffixed-form
FixedForm,
- /// -ffixed-form
+ /// -ffree-form
FreeForm
};
@@ -286,6 +286,10 @@ struct FrontendOptions {
// source file.
int fixedFormColumns = 72;
+ // The column after which characters are ignored in free form lines in the
+ // source file.
+ int freeFormColumns = 1000000;
+
/// The input kind, either specified via -x argument or deduced from the input
/// file name.
InputKind dashX;
diff --git a/flang/include/flang/Parser/options.h b/flang/include/flang/Parser/options.h
index e65f253748d26..6db23dcb6bf07 100644
--- a/flang/include/flang/Parser/options.h
+++ b/flang/include/flang/Parser/options.h
@@ -25,6 +25,7 @@ struct Options {
bool isFixedForm{false};
int fixedFormColumns{72};
+ int freeFormColumns{1000000};
common::LanguageFeatureControl features;
std::vector<std::string> searchDirectories;
std::vector<std::string> intrinsicModuleDirectories;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index fab1b792180c3..c3eccae8d2939 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -810,7 +810,8 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
// Set fixedFormColumns based on -ffixed-line-length=<value>
if (const auto *arg =
- args.getLastArg(clang::options::OPT_ffixed_line_length_EQ)) {
+ args.getLastArg(clang::options::OPT_ffixed_line_length_EQ,
+ clang::options::OPT_ffree_line_length_EQ)) {
llvm::StringRef argValue = llvm::StringRef(arg->getValue());
std::int64_t columns = -1;
if (argValue == "none") {
@@ -822,13 +823,15 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
diags.Report(clang::diag::err_drv_negative_columns)
<< arg->getOption().getName() << arg->getValue();
} else if (columns == 0) {
- opts.fixedFormColumns = 1000000;
+ columns = 1000000;
} else if (columns < 7) {
diags.Report(clang::diag::err_drv_small_columns)
<< arg->getOption().getName() << arg->getValue() << "7";
- } else {
- opts.fixedFormColumns = columns;
}
+ if (arg->getOption().matches(clang::options::OPT_ffixed_line_length_EQ))
+ opts.fixedFormColumns = columns;
+ else
+ opts.freeFormColumns = columns;
}
// Set conversion based on -fconvert=<value>
@@ -1871,6 +1874,7 @@ void CompilerInvocation::setFortranOpts() {
frontendOptions.fortranForm == FortranForm::FixedForm;
}
fortranOptions.fixedFormColumns = frontendOptions.fixedFormColumns;
+ fortranOptions.freeFormColumns = frontendOptions.freeFormColumns;
// -E
fortranOptions.prescanAndReformat =
diff --git a/flang/lib/Parser/parsing.cpp b/flang/lib/Parser/parsing.cpp
index 667d8d9297ecb..3bdbcb3fd1281 100644
--- a/flang/lib/Parser/parsing.cpp
+++ b/flang/lib/Parser/parsing.cpp
@@ -75,6 +75,7 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) {
messages_, *currentCooked_, preprocessor_, options.features};
prescanner.set_fixedForm(options.isFixedForm)
.set_fixedFormColumnLimit(options.fixedFormColumns)
+ .set_freeFormColumnLimit(options.freeFormColumns)
.set_preprocessingOnly(options.prescanAndReformat)
.set_expandIncludeLines(!options.prescanAndReformat ||
options.expandIncludeLinesInPreprocessedOutput)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 78537aef1fdfe..0c558b2241310 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -42,6 +42,7 @@ Prescanner::Prescanner(const Prescanner &that, Preprocessor &prepro,
backslashFreeFormContinuation_{that.backslashFreeFormContinuation_},
inFixedForm_{that.inFixedForm_},
fixedFormColumnLimit_{that.fixedFormColumnLimit_},
+ freeFormColumnLimit_{that.freeFormColumnLimit_},
encoding_{that.encoding_},
prescannerNesting_{that.prescannerNesting_ + 1},
skipLeadingAmpersand_{that.skipLeadingAmpersand_},
@@ -568,6 +569,8 @@ void Prescanner::SkipToEndOfLine() {
bool Prescanner::MustSkipToEndOfLine() const {
if (inFixedForm_ && column_ > fixedFormColumnLimit_ && !tabInCurrentLine_) {
return true; // skip over ignored columns in right margin (73:80)
+ } else if (!inFixedForm_ && column_ > freeFormColumnLimit_) {
+ return true; // inline comment goes to end of source line
} else if (*at_ == '!' && !inCharLiteral_ &&
(!inFixedForm_ || tabInCurrentLine_ || column_ != 6)) {
return InCompilerDirective() ||
diff --git a/flang/lib/Parser/prescan.h b/flang/lib/Parser/prescan.h
index 8f4f390d4ea37..2e511e4edf71e 100644
--- a/flang/lib/Parser/prescan.h
+++ b/flang/lib/Parser/prescan.h
@@ -68,6 +68,10 @@ class Prescanner {
fixedFormColumnLimit_ = limit;
return *this;
}
+ Prescanner &set_freeFormColumnLimit(int limit) {
+ freeFormColumnLimit_ = limit;
+ return *this;
+ }
Prescanner &AddCompilerDirectiveSentinel(const std::string &);
@@ -269,6 +273,7 @@ class Prescanner {
bool backslashFreeFormContinuation_{false};
bool inFixedForm_{false};
int fixedFormColumnLimit_{72};
+ int freeFormColumnLimit_{1000000};
Encoding encoding_{Encoding::UTF_8};
int parenthesisNesting_{0};
int prescannerNesting_{0};
diff --git a/flang/test/Driver/Inputs/free-line-length-test.f90 b/flang/test/Driver/Inputs/free-line-length-test.f90
new file mode 100644
index 0000000000000..dda2245ed34ce
--- /dev/null
+++ b/flang/test/Driver/Inputs/free-line-length-test.f90
@@ -0,0 +1,4 @@
+! The length of the line below is exactly 133 characters
+ program aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ end
+
diff --git a/flang/test/Driver/ffree-line-length.f90 b/flang/test/Driver/ffree-line-length.f90
new file mode 100644
index 0000000000000..9e54191181092
--- /dev/null
+++ b/flang/test/Driver/ffree-line-length.f90
@@ -0,0 +1,38 @@
+! Ensure argument -ffree-line-length=n works as expected.
+
+!--------------------------
+! FLANG DRIVER (flang)
+!--------------------------
+! RUN: %flang -E -Xflang -fno-reformat %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: not %flang -E -Xflang -fno-reformat -ffree-line-length=-2 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang -E -Xflang -fno-reformat -ffree-line-length=3 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang -E -Xflang -fno-reformat -ffree-line-length=none %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang -E -Xflang -fno-reformat -ffree-line-length=0 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang -E -Xflang -fno-reformat -ffree-line-length=13 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!----------------------------------------
+! FRONTEND FLANG DRIVER (flang -fc1)
+!----------------------------------------
+! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: not %flang_fc1 -E -fno-reformat -ffree-line-length=-2 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang_fc1 -E -fno-reformat -ffree-line-length=3 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang_fc1 -E -fno-reformat -ffree-line-length=none %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang_fc1 -E -fno-reformat -ffree-line-length=0 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang_fc1 -E -fno-reformat -ffree-line-length=13 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-------------------------------------
+! COMMAND ALIAS -ffree-line-length-n
+!-------------------------------------
+! RUN: %flang -E -Xflang -fno-reformat -ffree-line-length-13 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang_fc1 -E -fno-reformat -ffree-line-length-13 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+
+! NEGATIVELENGTH: invalid value '-2' in 'ffree-line-length=', value must be 'none' or a positive integer
+
+! INVALIDLENGTH: invalid value '3' in 'ffree-line-length=', value must be '7' or greater
+
+! The line should not be trimmed and should be read.
+! UNLIMITEDLENGTH: program {{(a{118})}}
+
+! LENGTH13: program
+
>From 9c85afc30593738bd50a1db1e31126cbf477340c Mon Sep 17 00:00:00 2001
From: Jean-Didier PAILLEUX <jean-di.pailleux at outlook.com>
Date: Tue, 21 Apr 2026 11:22:52 +0200
Subject: [PATCH 2/7] Update clang/include/clang/Options/Options.td
Co-authored-by: Tarun Prabhu <tarunprabhu at gmail.com>
---
clang/include/clang/Options/Options.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index da54596ede209..b78402d9c40fa 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7613,7 +7613,7 @@ def ffixed_line_length_EQ : Joined<["-"], "ffixed-line-length=">, Group<f_Group>
file}]>;
def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, Group<f_Group>, Alias<ffixed_line_length_EQ>;
def ffree_line_length_EQ : Joined<["-"], "ffree-line-length=">, Group<f_Group>,
- HelpText<"Use <value> as character line width in free mode">,
+ HelpText<"Use <value> as the maximum line width in free-form mode">,
DocBrief<[{Set column after which characters are ignored in typical free-form lines in the source
file}]>;
def ffree_line_length_VALUE : Joined<["-"], "ffree-line-length-">, Group<f_Group>, Alias<ffree_line_length_EQ>;
>From 7ca57f1b029168a55d84288b89c9a4bdf28eb30b Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Tue, 21 Apr 2026 13:30:08 +0200
Subject: [PATCH 3/7] Applying feedback and Update freeFormColums value based
on 6.3.2.1
---
flang/include/flang/Frontend/FrontendOptions.h | 4 +++-
flang/lib/Frontend/CompilerInvocation.cpp | 10 +++++++---
flang/lib/Parser/prescan.cpp | 2 +-
flang/test/Driver/ffree-line-length.f90 | 6 +++---
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 25683fc25f4b2..8149cb444f619 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -288,7 +288,9 @@ struct FrontendOptions {
// The column after which characters are ignored in free form lines in the
// source file.
- int freeFormColumns = 1000000;
+ // In 6.3.2.1, in free source form a line shall contain at most ten thousand
+ // characters.
+ int freeFormColumns = 10000;
/// The input kind, either specified via -x argument or deduced from the input
/// file name.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index c3eccae8d2939..44fa1e976dd4b 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -808,11 +808,14 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
: FortranForm::FreeForm;
}
- // Set fixedFormColumns based on -ffixed-line-length=<value>
+ // Set fixedFormColumns based on -ffixed-line-length=<value> or
+ // set freeFormColumns based on -ffree-line-length=<value>.
if (const auto *arg =
args.getLastArg(clang::options::OPT_ffixed_line_length_EQ,
clang::options::OPT_ffree_line_length_EQ)) {
llvm::StringRef argValue = llvm::StringRef(arg->getValue());
+ bool isFixedLineFlag =
+ arg->getOption().matches(clang::options::OPT_ffixed_line_length_EQ);
std::int64_t columns = -1;
if (argValue == "none") {
columns = 0;
@@ -824,11 +827,12 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
<< arg->getOption().getName() << arg->getValue();
} else if (columns == 0) {
columns = 1000000;
- } else if (columns < 7) {
+ } else if (columns < 7 && isFixedLineFlag) {
+ // Specific to the fixed form
diags.Report(clang::diag::err_drv_small_columns)
<< arg->getOption().getName() << arg->getValue() << "7";
}
- if (arg->getOption().matches(clang::options::OPT_ffixed_line_length_EQ))
+ if (isFixedLineFlag)
opts.fixedFormColumns = columns;
else
opts.freeFormColumns = columns;
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 0c558b2241310..036ae555b6ab9 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -570,7 +570,7 @@ bool Prescanner::MustSkipToEndOfLine() const {
if (inFixedForm_ && column_ > fixedFormColumnLimit_ && !tabInCurrentLine_) {
return true; // skip over ignored columns in right margin (73:80)
} else if (!inFixedForm_ && column_ > freeFormColumnLimit_) {
- return true; // inline comment goes to end of source line
+ return true;
} else if (*at_ == '!' && !inCharLiteral_ &&
(!inFixedForm_ || tabInCurrentLine_ || column_ != 6)) {
return InCompilerDirective() ||
diff --git a/flang/test/Driver/ffree-line-length.f90 b/flang/test/Driver/ffree-line-length.f90
index 9e54191181092..54a5f03a1f4d5 100644
--- a/flang/test/Driver/ffree-line-length.f90
+++ b/flang/test/Driver/ffree-line-length.f90
@@ -5,7 +5,7 @@
!--------------------------
! RUN: %flang -E -Xflang -fno-reformat %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
! RUN: not %flang -E -Xflang -fno-reformat -ffree-line-length=-2 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
-! RUN: not %flang -E -Xflang -fno-reformat -ffree-line-length=3 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: not %flang -E -Xflang -fno-reformat -ffree-line-length-abcd %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
! RUN: %flang -E -Xflang -fno-reformat -ffree-line-length=none %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
! RUN: %flang -E -Xflang -fno-reformat -ffree-line-length=0 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
! RUN: %flang -E -Xflang -fno-reformat -ffree-line-length=13 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=LENGTH13
@@ -15,7 +15,7 @@
!----------------------------------------
! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
! RUN: not %flang_fc1 -E -fno-reformat -ffree-line-length=-2 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
-! RUN: not %flang_fc1 -E -fno-reformat -ffree-line-length=3 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: not %flang_fc1 -E -fno-reformat -ffree-line-length-abcd %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
! RUN: %flang_fc1 -E -fno-reformat -ffree-line-length=none %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
! RUN: %flang_fc1 -E -fno-reformat -ffree-line-length=0 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
! RUN: %flang_fc1 -E -fno-reformat -ffree-line-length=13 %S/Inputs/free-line-length-test.f90 2>&1 | FileCheck %s --check-prefix=LENGTH13
@@ -29,7 +29,7 @@
! NEGATIVELENGTH: invalid value '-2' in 'ffree-line-length=', value must be 'none' or a positive integer
-! INVALIDLENGTH: invalid value '3' in 'ffree-line-length=', value must be '7' or greater
+! INVALIDLENGTH: invalid value 'abcd' in 'ffree-line-length=', value must be 'none' or a positive integer
! The line should not be trimmed and should be read.
! UNLIMITEDLENGTH: program {{(a{118})}}
>From fa959dadee75b1854b446cc57393609e2ba2f93c Mon Sep 17 00:00:00 2001
From: Jean-Didier PAILLEUX <jean-di.pailleux at outlook.com>
Date: Tue, 21 Apr 2026 17:07:30 +0200
Subject: [PATCH 4/7] Update flang/include/flang/Frontend/FrontendOptions.h
Co-authored-by: Tarun Prabhu <tarunprabhu at gmail.com>
---
flang/include/flang/Frontend/FrontendOptions.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 8149cb444f619..93aec9dec204c 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -288,7 +288,7 @@ struct FrontendOptions {
// The column after which characters are ignored in free form lines in the
// source file.
- // In 6.3.2.1, in free source form a line shall contain at most ten thousand
+ // In 6.3.2.1, in free form source a line shall contain at most ten thousand
// characters.
int freeFormColumns = 10000;
>From f5414b1f774411c4e2587c825aa95e772609895b Mon Sep 17 00:00:00 2001
From: Jean-Didier PAILLEUX <jean-di.pailleux at outlook.com>
Date: Tue, 21 Apr 2026 17:08:19 +0200
Subject: [PATCH 5/7] Update clang/include/clang/Options/Options.td
Co-authored-by: Tarun Prabhu <tarunprabhu at gmail.com>
---
clang/include/clang/Options/Options.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index b78402d9c40fa..f2d3768a2b043 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7614,7 +7614,7 @@ file}]>;
def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, Group<f_Group>, Alias<ffixed_line_length_EQ>;
def ffree_line_length_EQ : Joined<["-"], "ffree-line-length=">, Group<f_Group>,
HelpText<"Use <value> as the maximum line width in free-form mode">,
- DocBrief<[{Set column after which characters are ignored in typical free-form lines in the source
+ DocBrief<[{Set column after which characters are ignored in free-form lines in the source
file}]>;
def ffree_line_length_VALUE : Joined<["-"], "ffree-line-length-">, Group<f_Group>, Alias<ffree_line_length_EQ>;
def fconvert_EQ : Joined<["-"], "fconvert=">, Group<f_Group>,
>From bca26694a62e6d3392eb5df5831bed516a747fed Mon Sep 17 00:00:00 2001
From: Jean-Didier Pailleux <jean-didier.pailleux at sipearl.com>
Date: Wed, 22 Apr 2026 09:30:36 +0200
Subject: [PATCH 6/7] Update values of default column value + err message name
---
clang/include/clang/Basic/DiagnosticDriverKinds.td | 2 +-
flang/include/flang/Frontend/FrontendOptions.h | 4 ++--
flang/include/flang/Parser/options.h | 2 +-
flang/lib/Frontend/CompilerInvocation.cpp | 4 ++--
flang/test/Driver/Inputs/free-line-length-test.f90 | 6 +++---
flang/test/Driver/ffree-line-length.f90 | 4 ++--
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index f217180933b9b..7eba75663b4e9 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -412,7 +412,7 @@ def err_drv_unsupported_embed_bitcode
: Error<"%0 is not supported with -fembed-bitcode">;
def err_drv_bitcode_unsupported_on_toolchain : Error<
"-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
-def err_drv_negative_columns : Error<
+def err_drv_invalid_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">;
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 93aec9dec204c..409a88a7e50e4 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -288,8 +288,8 @@ struct FrontendOptions {
// The column after which characters are ignored in free form lines in the
// source file.
- // In 6.3.2.1, in free form source a line shall contain at most ten thousand
- // characters.
+ // In F2023 6.3.2.1 p1, in free form source a line shall contain at most ten
+ // thousand characters.
int freeFormColumns = 10000;
/// The input kind, either specified via -x argument or deduced from the input
diff --git a/flang/include/flang/Parser/options.h b/flang/include/flang/Parser/options.h
index 6db23dcb6bf07..adb01ae72639f 100644
--- a/flang/include/flang/Parser/options.h
+++ b/flang/include/flang/Parser/options.h
@@ -25,7 +25,7 @@ struct Options {
bool isFixedForm{false};
int fixedFormColumns{72};
- int freeFormColumns{1000000};
+ int freeFormColumns{10000};
common::LanguageFeatureControl features;
std::vector<std::string> searchDirectories;
std::vector<std::string> intrinsicModuleDirectories;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 44fa1e976dd4b..bd241b23681f3 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -823,10 +823,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
columns = -1;
}
if (columns < 0) {
- diags.Report(clang::diag::err_drv_negative_columns)
+ diags.Report(clang::diag::err_drv_invalid_columns)
<< arg->getOption().getName() << arg->getValue();
} else if (columns == 0) {
- columns = 1000000;
+ columns = 10000;
} else if (columns < 7 && isFixedLineFlag) {
// Specific to the fixed form
diags.Report(clang::diag::err_drv_small_columns)
diff --git a/flang/test/Driver/Inputs/free-line-length-test.f90 b/flang/test/Driver/Inputs/free-line-length-test.f90
index dda2245ed34ce..5eadb19c378ae 100644
--- a/flang/test/Driver/Inputs/free-line-length-test.f90
+++ b/flang/test/Driver/Inputs/free-line-length-test.f90
@@ -1,4 +1,4 @@
-! The length of the line below is exactly 133 characters
- program aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- end
+! The length of the line below is exactly 35 characters
+program arbitrary_program_test_name
+end
diff --git a/flang/test/Driver/ffree-line-length.f90 b/flang/test/Driver/ffree-line-length.f90
index 54a5f03a1f4d5..0d1b58855332e 100644
--- a/flang/test/Driver/ffree-line-length.f90
+++ b/flang/test/Driver/ffree-line-length.f90
@@ -32,7 +32,7 @@
! INVALIDLENGTH: invalid value 'abcd' in 'ffree-line-length=', value must be 'none' or a positive integer
! The line should not be trimmed and should be read.
-! UNLIMITEDLENGTH: program {{(a{118})}}
+! UNLIMITEDLENGTH: program arbitrary_program_test_name
-! LENGTH13: program
+! LENGTH13: program arbit
>From f2b335f85d862afa2a0a9cd3e959f4130111c838 Mon Sep 17 00:00:00 2001
From: Jean-Didier PAILLEUX <jean-di.pailleux at outlook.com>
Date: Thu, 23 Apr 2026 14:29:53 +0200
Subject: [PATCH 7/7] Update flang/test/Driver/Inputs/free-line-length-test.f90
Co-authored-by: Tarun Prabhu <tarunprabhu at gmail.com>
---
flang/test/Driver/Inputs/free-line-length-test.f90 | 1 -
1 file changed, 1 deletion(-)
diff --git a/flang/test/Driver/Inputs/free-line-length-test.f90 b/flang/test/Driver/Inputs/free-line-length-test.f90
index 5eadb19c378ae..d436ffedcda32 100644
--- a/flang/test/Driver/Inputs/free-line-length-test.f90
+++ b/flang/test/Driver/Inputs/free-line-length-test.f90
@@ -1,4 +1,3 @@
! The length of the line below is exactly 35 characters
program arbitrary_program_test_name
end
-
More information about the flang-commits
mailing list