[flang-commits] [clang] [flang] [flang][driver] add negative from of -fsave-main-program (PR #124110)
via flang-commits
flang-commits at lists.llvm.org
Fri Jan 24 06:55:46 PST 2025
https://github.com/jeanPerier updated https://github.com/llvm/llvm-project/pull/124110
>From 28dba56b12b45f8ce82426e2b79165352f549850 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Thu, 23 Jan 2025 04:37:30 -0800
Subject: [PATCH 1/3] [flang][driver] add negative from of -fsave-main-program
---
clang/include/clang/Driver/Options.td | 4 ++--
clang/lib/Driver/ToolChains/Flang.cpp | 3 ++-
flang/lib/Frontend/CompilerInvocation.cpp | 9 +++++----
flang/test/Driver/fsave-main-program.f90 | 6 +++++-
flang/test/Lower/fsave-main-program.f90 | 1 +
5 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index df705104d9ea31..6fface303c57a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6968,8 +6968,8 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables UNSIGNED type">;
def fno_automatic : Flag<["-"], "fno-automatic">, Group<f_Group>,
HelpText<"Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE">;
-def fsave_main_program : Flag<["-"], "fsave-main-program">, Group<f_Group>,
- HelpText<"Place all variables from the main program in static memory (otherwise scalars may be placed on the stack)">;
+defm save_main_program : OptInFC1FFlag<"save-main-program",
+ "Place all variables from the main program in static memory (otherwise scalars may be placed on the stack)">;
defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
PosFlag<SetTrue, [], [ClangOption], "Attempt to allocate array temporaries on the stack, no matter their size">,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 9c1fd28a3a8a26..8d1ec016325dfb 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -58,7 +58,8 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
options::OPT_fhermetic_module_files,
options::OPT_frealloc_lhs,
options::OPT_fno_realloc_lhs,
- options::OPT_fsave_main_program});
+ options::OPT_fsave_main_program,
+ options::OPT_fno_save_main_program});
}
void Flang::addPreprocessingOptions(const ArgList &Args,
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 3c6da4687f65d3..68b5950d3a51b7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -770,10 +770,11 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
opts.features.Enable(Fortran::common::LanguageFeature::DefaultSave);
}
- // -fsave-main-program
- if (args.hasArg(clang::driver::options::OPT_fsave_main_program)) {
- opts.features.Enable(Fortran::common::LanguageFeature::SaveMainProgram);
- }
+ // -f{no}-save-main-program
+ opts.features.Enable(
+ Fortran::common::LanguageFeature::SaveMainProgram,
+ args.hasFlag(clang::driver::options::OPT_fsave_main_program,
+ clang::driver::options::OPT_fno_save_main_program, false));
if (args.hasArg(
clang::driver::options::OPT_falternative_parameter_statement)) {
diff --git a/flang/test/Driver/fsave-main-program.f90 b/flang/test/Driver/fsave-main-program.f90
index bffdfd97911e80..e7a2f9d8b470ed 100644
--- a/flang/test/Driver/fsave-main-program.f90
+++ b/flang/test/Driver/fsave-main-program.f90
@@ -1,5 +1,9 @@
! Check that the driver passes through -fsave-main-program:
! RUN: %flang -### -S -fsave-main-program %s -o - 2>&1 | FileCheck %s
+! CHECK: "-fc1"{{.*}}"-fsave-main-program"
+
+! RUN: %flang -### -S -fno-save-main-program %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK2
+! CHECK2: "-fc1"{{.*}}"-fno-save-main-program"
+
! Check that the compiler accepts -fsave-main-program:
! RUN: %flang_fc1 -emit-hlfir -fsave-main-program %s -o -
-! CHECK: "-fc1"{{.*}}"-fsave-main-program"
diff --git a/flang/test/Lower/fsave-main-program.f90 b/flang/test/Lower/fsave-main-program.f90
index 17fc1b02f5068f..e89244c3c7c51a 100644
--- a/flang/test/Lower/fsave-main-program.f90
+++ b/flang/test/Lower/fsave-main-program.f90
@@ -1,6 +1,7 @@
! Test -fsave-main-program switch.
! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
! RUN: %flang_fc1 -fsave-main-program -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-SAVE %s
+! RUN: %flang_fc1 -fsave-main-program -fno-save-main-program -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
program test
integer :: i
call foo(i)
>From 7b9fe8a3f1f8d2a308d80ddc6d259ce4e4cda6b6 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Thu, 23 Jan 2025 07:06:44 -0800
Subject: [PATCH 2/3] Also print the negative form in the help
I had not noticed that with OptInFC1FFlag, the negative form
is hidden.
---
clang/include/clang/Driver/Options.td | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 6fface303c57a6..6ebc1bd05eb082 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6968,8 +6968,11 @@ defm unsigned : OptInFC1FFlag<"unsigned", "Enables UNSIGNED type">;
def fno_automatic : Flag<["-"], "fno-automatic">, Group<f_Group>,
HelpText<"Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE">;
-defm save_main_program : OptInFC1FFlag<"save-main-program",
- "Place all variables from the main program in static memory (otherwise scalars may be placed on the stack)">;
+defm save_main_program : BoolOptionWithoutMarshalling<"f", "save-main-program",
+ PosFlag<SetTrue, [], [ClangOption],
+ "Place all main program variables in static memory (otherwise scalars may be placed on the stack)">,
+ NegFlag<SetFalse, [], [ClangOption],
+ "Allow placing main program variables on the stack (default)">>;
defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
PosFlag<SetTrue, [], [ClangOption], "Attempt to allocate array temporaries on the stack, no matter their size">,
>From 0ce7afcfc9bdf4f5bbe93191f8c5d805135dc8ed Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Fri, 24 Jan 2025 06:55:14 -0800
Subject: [PATCH 3/3] remove misleading overridden visibility
---
clang/include/clang/Driver/Options.td | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 6ebc1bd05eb082..069935e7fb5f5b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6969,9 +6969,9 @@ def fno_automatic : Flag<["-"], "fno-automatic">, Group<f_Group>,
HelpText<"Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE">;
defm save_main_program : BoolOptionWithoutMarshalling<"f", "save-main-program",
- PosFlag<SetTrue, [], [ClangOption],
+ PosFlag<SetTrue, [], [],
"Place all main program variables in static memory (otherwise scalars may be placed on the stack)">,
- NegFlag<SetFalse, [], [ClangOption],
+ NegFlag<SetFalse, [], [],
"Allow placing main program variables on the stack (default)">>;
defm stack_arrays : BoolOptionWithoutMarshalling<"f", "stack-arrays",
More information about the flang-commits
mailing list