Skip to content

Commit 7029f71

Browse files
committed
[flang][Driver] Add support of -fd-lines-as-comments and -fd-lines-as-code flags
1 parent 2077d40 commit 7029f71

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6747,8 +6747,16 @@ defm backtrace : BooleanFFlag<"backtrace">, Group<gfortran_Group>;
67476747
defm bounds_check : BooleanFFlag<"bounds-check">, Group<gfortran_Group>;
67486748
defm check_array_temporaries : BooleanFFlag<"check-array-temporaries">, Group<gfortran_Group>;
67496749
defm cray_pointer : BooleanFFlag<"cray-pointer">, Group<gfortran_Group>;
6750-
defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group<gfortran_Group>;
6751-
defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, Group<gfortran_Group>;
6750+
defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">,
6751+
HelpText<"Treat fixed form lines with 'd' or 'D' in the "
6752+
"first column as blank.">,
6753+
Group<gfortran_Group>,
6754+
Visibility<[FlangOption, FC1Option]>;
6755+
defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">,
6756+
HelpText<"Treat fixed form lines with 'd' or 'D' in "
6757+
"the first column as comments.">,
6758+
Group<gfortran_Group>,
6759+
Visibility<[FlangOption, FC1Option]>;
67526760
defm dollar_ok : BooleanFFlag<"dollar-ok">, Group<gfortran_Group>;
67536761
defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, Group<gfortran_Group>;
67546762
defm dump_fortran_original : BooleanFFlag<"dump-fortran-original">, Group<gfortran_Group>;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
6060
options::OPT_frealloc_lhs,
6161
options::OPT_fno_realloc_lhs,
6262
options::OPT_fsave_main_program,
63+
options::OPT_fd_lines_as_code,
64+
options::OPT_fd_lines_as_comments,
6365
options::OPT_fno_save_main_program});
6466
}
6567

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,32 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
957957
clang::DiagnosticsEngine &diags) {
958958
unsigned numErrorsBefore = diags.getNumErrors();
959959

960+
// -fd-lines-as-code
961+
if (args.hasArg(clang::driver::options::OPT_fd_lines_as_code)) {
962+
if (res.getFrontendOpts().fortranForm == FortranForm::FreeForm) {
963+
const unsigned fdLinesAsWarning = diags.getCustomDiagID(
964+
clang::DiagnosticsEngine::Warning,
965+
"‘-fd-lines-as-code’ has no effect in free form.");
966+
diags.Report(fdLinesAsWarning);
967+
} else {
968+
res.getFrontendOpts().features.Enable(
969+
Fortran::common::LanguageFeature::OldDebugLines, true);
970+
}
971+
}
972+
973+
// -fd-lines-as-comments
974+
if (args.hasArg(clang::driver::options::OPT_fd_lines_as_comments)) {
975+
if (res.getFrontendOpts().fortranForm == FortranForm::FreeForm) {
976+
const unsigned fdLinesAsWarning = diags.getCustomDiagID(
977+
clang::DiagnosticsEngine::Warning,
978+
"‘-fd-lines-as-comments’ has no effect in free form.");
979+
diags.Report(fdLinesAsWarning);
980+
} else {
981+
res.getFrontendOpts().features.Enable(
982+
Fortran::common::LanguageFeature::OldDebugLines, false);
983+
}
984+
}
985+
960986
// -fdefault* family
961987
if (args.hasArg(clang::driver::options::OPT_fdefault_real_8)) {
962988
res.getDefaultKinds().set_defaultRealKind(8);

flang/test/Driver/fd-lines-as.f90

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
! Ensure arguments -fd-lines-as-comments and -fd-lines-as-code as expected.
2+
3+
!--------------------------
4+
! FLANG DRIVER (flang)
5+
!--------------------------
6+
! Default behavior is equivalent as -fd-lines-as-comments
7+
!--------------------------
8+
! RUN: %flang -fsyntax-only -ffixed-form %s 2>&1
9+
! RUN: %flang -fsyntax-only -ffixed-form -fd-lines-as-comments %s 2>&1
10+
! RUN: not %flang -fsyntax-only -ffixed-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=CODE
11+
! RUN: not %flang -fsyntax-only -ffree-form -fd-lines-as-comments %s 2>&1 | FileCheck %s --check-prefix=WARNING-COMMENTS
12+
! RUN: not %flang -fsyntax-only -ffree-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=WARNING-CODE
13+
14+
!----------------------------------------
15+
! FRONTEND FLANG DRIVER (flang -fc1)
16+
!----------------------------------------
17+
! RUN: %flang_fc1 -fsyntax-only -ffixed-form %s 2>&1
18+
! RUN: %flang_fc1 -fsyntax-only -ffixed-form -fd-lines-as-comments %s 2>&1
19+
! RUN: not %flang_fc1 -fsyntax-only -ffixed-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=CODE
20+
! RUN: not %flang_fc1 -fsyntax-only -ffree-form -fd-lines-as-comments %s 2>&1 | FileCheck %s --check-prefix=WARNING-COMMENTS
21+
! RUN: not %flang_fc1 -fsyntax-only -ffree-form -fd-lines-as-code %s 2>&1 | FileCheck %s --check-prefix=WARNING-CODE
22+
23+
! CODE: Semantic errors
24+
! WARNING-COMMENTS: warning: ‘-fd-lines-as-comments’ has no effect in free form.
25+
! WARNING-CODE: warning: ‘-fd-lines-as-code’ has no effect in free form.
26+
27+
program FixedForm
28+
d end
29+
end

0 commit comments

Comments
 (0)