-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][Driver] Add support of -fd-lines-as-comments and -fd-lines-as-code flags #127605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Jean-Didier PAILLEUX (JDPailleux) Changes
Full diff: https://github.com/llvm/llvm-project/pull/127605.diff 4 Files Affected:
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
|
@llvm/pr-subscribers-flang-driver Author: Jean-Didier PAILLEUX (JDPailleux) Changes
Full diff: https://github.com/llvm/llvm-project/pull/127605.diff 4 Files Affected:
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
|
Do the tests added in this patch check this behaviour? |
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]>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add help messages for these options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File updated with help messages.
dafaaa9
to
2adb56d
Compare
Yes, if the source file is compiled with |
HelpText<"In fixed form, with lines beginning with 'd' or 'D', the lines " | ||
"will be treated as a comment.">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rephrasing
HelpText<"In fixed form, with lines beginning with 'd' or 'D', the lines " | |
"will be treated as a comment.">, | |
HelpText<"In fixed form, lines beginning with 'd' or 'D' are" | |
"treated as comment lines">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another suggestion:
"Treat fixed form lines with 'd' or 'D' in the first column as comments."
I think the 'd'/'D' is required to be in the first column.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help text updated
HelpText<"In fixed form, with lines beginning with 'd' or 'D', the first " | ||
"column will be treated as if it contained a blank.">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rephrasing
HelpText<"In fixed form, with lines beginning with 'd' or 'D', the first " | |
"column will be treated as if it contained a blank.">, | |
HelpText<"In fixed form, lines beginning with 'd' or 'D' are treated " | |
"as if the first column contained a blank.">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another suggestion:
"Treat 'd' or 'D' in the first column of fixed form lines as a blank."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Help text updated
2adb56d
to
7029f71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Jean-Didier
Thanks. I wondered whether there is a better way to test this (by unparse or inspecting the output of |
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<gfortran_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<gfortran_Group>, | ||
Visibility<[FlangOption, FC1Option]>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move these to the f_Group as done in other patches (#120165)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch Kiran!
It looks like the gfortran_Group
was created in 2013, well before flang
. I assume that his was from back when clang
would silently pass unsupported files to gfortran
. The patch you referenced does not seem to have moved a known option to f_Group
. But it does seem like the right thing to do.
Do we want to eventually move all supported gfortran
flags to f_Group
? If so, we can start with this and move the others over in time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to f_Group
done.
Why keep gfortran_group
unless it's to specify that a flag of this group is not supported by flang?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gfortran_group
was probably used once in llvm to drive gcc/gfortran. I don't think anyone uses it these days.
7029f71
to
75c8eb0
Compare
Test added by inspecting the output of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for seeing this through.
Hi, thanks you for the approvals ! |
…-code flags (llvm#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.
-fd-lines-as-code
and-fd-lines-as-comments
enables treatment for lines beginning withd
orD
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.