Author: Jean-Didier PAILLEUX Date: 2025-03-03T11:55:36Z New Revision: 370d34fe40162946905b900097ed746dd4aeb6ad
URL: https://github.com/llvm/llvm-project/commit/370d34fe40162946905b900097ed746dd4aeb6ad DIFF: https://github.com/llvm/llvm-project/commit/370d34fe40162946905b900097ed746dd4aeb6ad.diff LOG: [flang][Driver] Add support of -fd-lines-as-comments and -fd-lines-as-code flags (#127605) `-fd-lines-as-code` and `-fd-lines-as-comments` enables treatment for lines beginning with `d` or `D` in fixed form sources. Using these options in free form has no effect. If the `-fd-lines-as-code` option is given they are treated as if the first column contained a blank. If the `-fd-lines-as-comments` option is given, they are treated as comment lines. Added: flang/test/Driver/fd-lines-as.f90 flang/test/Preprocessing/fd-lines-as.f90 Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Flang.cpp flang/lib/Frontend/CompilerInvocation.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 75b1c51445942..c4bd030e32b5b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6777,8 +6777,16 @@ defm backtrace : BooleanFFlag<"backtrace">, Group<gfortran_Group>; defm bounds_check : BooleanFFlag<"bounds-check">, Group<gfortran_Group>; defm check_array_temporaries : BooleanFFlag<"check-array-temporaries">, Group<gfortran_Group>; defm cray_pointer : BooleanFFlag<"cray-pointer">, Group<gfortran_Group>; -defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group<gfortran_Group>; -defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, Group<gfortran_Group>; +defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, + HelpText<"Treat fixed form lines with 'd' or 'D' in the " + "first column as blank.">, + Group<f_Group>, + Visibility<[FlangOption, FC1Option]>; +defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, + HelpText<"Treat fixed form lines with 'd' or 'D' in " + "the first column as comments.">, + Group<f_Group>, + Visibility<[FlangOption, FC1Option]>; defm dollar_ok : BooleanFFlag<"dollar-ok">, Group<gfortran_Group>; defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, Group<gfortran_Group>; defm dump_fortran_original : BooleanFFlag<"dump-fortran-original">, Group<gfortran_Group>; diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 45c26cf8c3159..d4fea633d0edf 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -60,6 +60,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args, options::OPT_frealloc_lhs, options::OPT_fno_realloc_lhs, options::OPT_fsave_main_program, + options::OPT_fd_lines_as_code, + options::OPT_fd_lines_as_comments, options::OPT_fno_save_main_program}); } diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 724316f1b30c7..8b07a50824899 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -961,6 +961,32 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args, clang::DiagnosticsEngine &diags) { unsigned numErrorsBefore = diags.getNumErrors(); + // -fd-lines-as-code + if (args.hasArg(clang::driver::options::OPT_fd_lines_as_code)) { + if (res.getFrontendOpts().fortranForm == FortranForm::FreeForm) { + const unsigned fdLinesAsWarning = diags.getCustomDiagID( + clang::DiagnosticsEngine::Warning, + "‘-fd-lines-as-code’ has no effect in free form."); + diags.Report(fdLinesAsWarning); + } else { + res.getFrontendOpts().features.Enable( + Fortran::common::LanguageFeature::OldDebugLines, true); + } + } + + // -fd-lines-as-comments + if (args.hasArg(clang::driver::options::OPT_fd_lines_as_comments)) { + if (res.getFrontendOpts().fortranForm == FortranForm::FreeForm) { + const unsigned fdLinesAsWarning = diags.getCustomDiagID( + clang::DiagnosticsEngine::Warning, + "‘-fd-lines-as-comments’ has no effect in free form."); + diags.Report(fdLinesAsWarning); + } else { + res.getFrontendOpts().features.Enable( + Fortran::common::LanguageFeature::OldDebugLines, false); + } + } + // -fdefault* family if (args.hasArg(clang::driver::options::OPT_fdefault_real_8)) { res.getDefaultKinds().set_defaultRealKind(8); diff --git a/flang/test/Driver/fd-lines-as.f90 b/flang/test/Driver/fd-lines-as.f90 new file mode 100644 index 0000000000000..ea06a39378e28 --- /dev/null +++ b/flang/test/Driver/fd-lines-as.f90 @@ -0,0 +1,29 @@ +! Ensure arguments -fd-lines-as-comments and -fd-lines-as-code as expected. + +!-------------------------- +! FLANG DRIVER (flang) +!-------------------------- +! Default behavior is equivalent as -fd-lines-as-comments +!-------------------------- +! RUN: %flang -fsyntax-only -ffixed-form %s 2>&1 +! RUN: %flang -fsyntax-only -ffixed-form -fd-lines-as-comments %s 2>&1 +! RUN: not %flang -fsyntax-only -ffixed-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=CODE +! RUN: not %flang -fsyntax-only -ffree-form -fd-lines-as-comments %s 2>&1 | FileCheck %s --check-prefix=WARNING-COMMENTS +! RUN: not %flang -fsyntax-only -ffree-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=WARNING-CODE + +!---------------------------------------- +! FRONTEND FLANG DRIVER (flang -fc1) +!---------------------------------------- +! RUN: %flang_fc1 -fsyntax-only -ffixed-form %s 2>&1 +! RUN: %flang_fc1 -fsyntax-only -ffixed-form -fd-lines-as-comments %s 2>&1 +! RUN: not %flang_fc1 -fsyntax-only -ffixed-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=CODE +! RUN: not %flang_fc1 -fsyntax-only -ffree-form -fd-lines-as-comments %s 2>&1 | FileCheck %s --check-prefix=WARNING-COMMENTS +! RUN: not %flang_fc1 -fsyntax-only -ffree-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=WARNING-CODE + +! CODE: Semantic errors +! WARNING-COMMENTS: warning: ‘-fd-lines-as-comments’ has no effect in free form. +! WARNING-CODE: warning: ‘-fd-lines-as-code’ has no effect in free form. + + program FixedForm +d end + end diff --git a/flang/test/Preprocessing/fd-lines-as.f90 b/flang/test/Preprocessing/fd-lines-as.f90 new file mode 100644 index 0000000000000..bae40e5ccdb20 --- /dev/null +++ b/flang/test/Preprocessing/fd-lines-as.f90 @@ -0,0 +1,23 @@ +! Ensure arguments -fd-lines-as-comments and -fd-lines-as-code display the correct output with -E. + +!-------------------------- +! Default behavior is equivalent as -fd-lines-as-comments +!-------------------------- +! RUN: %flang -E -ffixed-form %s 2>&1 | FileCheck %s --check-prefix=COMMENT +! RUN: %flang -E -ffixed-form -fd-lines-as-comments %s 2>&1 | FileCheck %s --check-prefix=COMMENT +! RUN: %flang -E -ffixed-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=CODE + + program FixedForm +d end +D end + end + +! COMMENT: program FixedForm +! COMMENT: end +! COMMENT-NOT: end +! COMMENT-NOT: end + +! CODE: program FixedForm +! CODE: end +! CODE: end +! CODE: end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits