https://github.com/TZT123-a11y updated https://github.com/llvm/llvm-project/pull/173833
>From 8c5bd71687a4acc2a9d68db8050751ec71bbbdb8 Mon Sep 17 00:00:00 2001 From: tanzht <[email protected]> Date: Mon, 29 Dec 2025 15:29:06 +0800 Subject: [PATCH 1/4] To be compatible with classic flang, add the -Mextend compilation option --- clang/include/clang/Options/Options.td | 3 +++ clang/lib/Driver/ToolChains/Flang.cpp | 1 + flang/lib/Frontend/CompilerInvocation.cpp | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 8cd31a3be109a..9b99a1e90ceaa 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -7333,6 +7333,9 @@ 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 Mextend : Flag<["-"], "Mextend">, Group<f_Group>, + HelpText<"Classic Flang compat: Allow 132-column lines in fixed form">, + Visibility<[FC1Option, FlangOption]>; 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 558a27e5adcc5..bc65d392699cf 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -38,6 +38,7 @@ void Flang::addFortranDialectOptions(const ArgList &Args, ArgStringList &CmdArgs) const { Args.addAllArgs(CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form, + options::OPT_Mextend, options::OPT_ffixed_line_length_EQ, options::OPT_fopenacc, options::OPT_finput_charset_EQ, diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index dd25cdc0e5707..7046e7eb6a690 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -1546,10 +1546,29 @@ static bool parseLangOptionsArgs(CompilerInvocation &invoc, return success; } +static llvm::SmallVector<const char *> +replaceClassicFlangArgs(llvm::ArrayRef<const char *> CommandLineArgs) { + llvm::SmallVector<const char *> NewArgs; + for (auto Arg : CommandLineArgs) { + // Process -mextend -> mapping to -ffixed-line-length=132 + if (std::strcmp(Arg, "-Mextend") == 0) { + NewArgs.push_back("-ffixed-line-length=132"); + } + else { + NewArgs.push_back(Arg); + } + } + return NewArgs; +} + bool CompilerInvocation::createFromArgs( - CompilerInvocation &invoc, llvm::ArrayRef<const char *> commandLineArgs, + CompilerInvocation &invoc, llvm::ArrayRef<const char *> commandLineArgs0, clang::DiagnosticsEngine &diags, const char *argv0) { + auto NewCommandLineArgs = + replaceClassicFlangArgs(commandLineArgs0); + llvm::ArrayRef<const char *> commandLineArgs = NewCommandLineArgs; + bool success = true; // Set the default triple for this CompilerInvocation. This might be >From a93054280c3a3349a8531b8de38f919a3ddf1d59 Mon Sep 17 00:00:00 2001 From: tanzht <[email protected]> Date: Tue, 6 Jan 2026 11:20:50 +0800 Subject: [PATCH 2/4] Handle the parameter conversion from -Mextend to -ffixed-line-length=132 in the compiler driver --- clang/lib/Driver/ToolChains/Flang.cpp | 11 ++++++++++- flang/lib/Frontend/CompilerInvocation.cpp | 21 +-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index bc65d392699cf..deeef49eeb306 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -36,9 +36,18 @@ static void addDashXForInput(const ArgList &Args, const InputInfo &Input, void Flang::addFortranDialectOptions(const ArgList &Args, ArgStringList &CmdArgs) const { + // Handle the -Mextend parameter + if (Arg *A = Args.getLastArg(options::OPT_Mextend)) { + // Check if -ffixed-line-length has been specified + if (!Args.hasArg(options::OPT_ffixed_line_length_EQ)) { + CmdArgs.push_back("-ffixed-line-length=132"); + } + // If the user specifies both -Mextend and -ffixed-line-length=N, + // Then -ffixed-line-length=N will override -Mextend + } + Args.addAllArgs(CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form, - options::OPT_Mextend, options::OPT_ffixed_line_length_EQ, options::OPT_fopenacc, options::OPT_finput_charset_EQ, diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index a56b6072439ae..4fb1d91306745 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -1546,29 +1546,10 @@ static bool parseLangOptionsArgs(CompilerInvocation &invoc, return success; } -static llvm::SmallVector<const char *> -replaceClassicFlangArgs(llvm::ArrayRef<const char *> CommandLineArgs) { - llvm::SmallVector<const char *> NewArgs; - for (auto Arg : CommandLineArgs) { - // Process -mextend -> mapping to -ffixed-line-length=132 - if (std::strcmp(Arg, "-Mextend") == 0) { - NewArgs.push_back("-ffixed-line-length=132"); - } - else { - NewArgs.push_back(Arg); - } - } - return NewArgs; -} - bool CompilerInvocation::createFromArgs( - CompilerInvocation &invoc, llvm::ArrayRef<const char *> commandLineArgs0, + CompilerInvocation &invoc, llvm::ArrayRef<const char *> commandLineArgs, clang::DiagnosticsEngine &diags, const char *argv0) { - auto NewCommandLineArgs = - replaceClassicFlangArgs(commandLineArgs0); - llvm::ArrayRef<const char *> commandLineArgs = NewCommandLineArgs; - bool success = true; // Set the default triple for this CompilerInvocation. This might be >From e8bb88bda2f64810c2492910a4c316ab5d1bb62c Mon Sep 17 00:00:00 2001 From: tanzht <[email protected]> Date: Tue, 6 Jan 2026 11:33:31 +0800 Subject: [PATCH 3/4] Add the test case mextend.f90 of -Mextend in flang/test/driver --- flang/test/Driver/mextend.f90 | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 flang/test/Driver/mextend.f90 diff --git a/flang/test/Driver/mextend.f90 b/flang/test/Driver/mextend.f90 new file mode 100644 index 0000000000000..cfbb3b13ef6af --- /dev/null +++ b/flang/test/Driver/mextend.f90 @@ -0,0 +1,53 @@ +! Test that -Mextend option is properly converted to -ffixed-line-length=132 +! and that explicit -ffixed-line-length overrides -Mextend. + +! RUN: %flang -### -Mextend %s 2>&1 | FileCheck %s +! RUN: %flang -### -Mextend -ffixed-line-length=80 %s 2>&1 | FileCheck %s --check-prefix=OVERRIDE +! RUN: %flang -### -ffixed-line-length=100 %s 2>&1 | FileCheck %s --check-prefix=EXPLICIT +! RUN: %flang -### -Mextend -ffixed-form %s 2>&1 | FileCheck %s --check-prefix=FIXEDFORM +! RUN: %flang -### -Mextend -ffree-form %s 2>&1 | FileCheck %s --check-prefix=FREEFORM + +! CHECK: flang{{.*}}-fc1 +! CHECK-SAME: -ffixed-line-length=132 +! CHECK-NOT: -Mextend + +! Test that explicit -ffixed-line-length=80 overrides -Mextend +! OVERRIDE: flang{{.*}}-fc1 +! OVERRIDE-SAME: -ffixed-line-length=80 +! OVERRIDE-NOT: -ffixed-line-length=132 +! OVERRIDE-NOT: -Mextend + +! Test that just -ffixed-line-length=100 works +! EXPLICIT: flang{{.*}}-fc1 +! EXPLICIT-SAME: -ffixed-line-length=100 +! EXPLICIT-NOT: -Mextend + +! Test that -Mextend works with -ffixed-form +! FIXEDFORM: flang{{.*}}-fc1 +! FIXEDFORM-SAME: -ffixed-line-length=132 +! FIXEDFORM-SAME: -ffixed-form +! FIXEDFORM-NOT: -Mextend + +! Test that -Mextend works with -ffree-form +! FREEFORM: flang{{.*}}-fc1 +! FREEFORM-SAME: -ffixed-line-length=132 +! FREEFORM-SAME: -ffree-form +! FREEFORM-NOT: -Mextend + +! Dummy Fortran code to compile +program test_mextend + implicit none + integer :: i, j, k + real :: x, y, z + + ! A long line to test extended line length + ! 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012 + x = 1.0 + y = 2.0 + z = x + y + + print *, "Test -Mextend option" + print *, "x = ", x + print *, "y = ", y + print *, "z = ", z +end program test_mextend \ No newline at end of file >From 12f45a294f05224abdb7557ac7fb77fa7552d560 Mon Sep 17 00:00:00 2001 From: tanzht <[email protected]> Date: Tue, 6 Jan 2026 15:24:41 +0800 Subject: [PATCH 4/4] Fix clang-format issues --- clang/lib/Driver/ToolChains/Flang.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index deeef49eeb306..17bef6a3382b9 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -45,7 +45,7 @@ void Flang::addFortranDialectOptions(const ArgList &Args, // If the user specifies both -Mextend and -ffixed-line-length=N, // Then -ffixed-line-length=N will override -Mextend } - + Args.addAllArgs(CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form, options::OPT_ffixed_line_length_EQ, _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
