llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Jean-Didier PAILLEUX (JDPailleux) <details> <summary>Changes</summary> `-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. --- Full diff: https://github.com/llvm/llvm-project/pull/127605.diff 4 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+6-2) - (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2) - (modified) flang/lib/Frontend/CompilerInvocation.cpp (+26) - (added) flang/test/Driver/fd-lines-as.f90 (+29) ``````````diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5ad187926e710..ac0103cabda07 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6747,8 +6747,12 @@ 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">, + Group<gfortran_Group>, + Visibility<[FlangOption, FC1Option]>; +defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, + Group<gfortran_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 9ad795edd724d..4c452491fa415 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 f3d9432c62d3b..55283e1279f2f 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -957,6 +957,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 auto 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 auto 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 `````````` </details> https://github.com/llvm/llvm-project/pull/127605 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits