https://github.com/TZT123-a11y created https://github.com/llvm/llvm-project/pull/173833
To maintain backward compatibility with the classic Flang compiler, support for the -Mextend compilation option has been added. Classic Flang uses the -Mextend option to allow fixed-format Fortran code to have a 132-column extended length, while modern Flang (based on LLVM) uses the -ffixed-line-length=132 option to achieve the same functionality. >From 8c5bd71687a4acc2a9d68db8050751ec71bbbdb8 Mon Sep 17 00:00:00 2001 From: tanzht <[email protected]> Date: Mon, 29 Dec 2025 15:29:06 +0800 Subject: [PATCH] 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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
