[clang] d81f633 - [flang][driver] Add -Xflang and make -test-io a frontend-only flang

Andrzej Warzynski via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 22 02:11:55 PST 2021


Author: Andrzej Warzynski
Date: 2021-02-22T10:11:43Z
New Revision: d81f633fe28fd23108b4dc8c25548f1653ba0cd2

URL: https://github.com/llvm/llvm-project/commit/d81f633fe28fd23108b4dc8c25548f1653ba0cd2
DIFF: https://github.com/llvm/llvm-project/commit/d81f633fe28fd23108b4dc8c25548f1653ba0cd2.diff

LOG: [flang][driver] Add -Xflang and make -test-io a frontend-only flang

This patch adds support for `-Xflang` in `flang-new`. The semantics are
identical to `-Xclang`.

With the addition of `-Xflang`, we can modify `-test-io` to be a
compiler-frontend only flag. This makes more sense, this flag is:
  * very frontend specific
  * to be used for development and testing only
  * not to be exposed to the end user
Originally we added it to the compiler driver, `flang-new`, in order to
facilitate testing. With `-Xflang` this is no longer needed. Tests are
updated accordingly.

Differential Revision: https://reviews.llvm.org/D96864

Added: 
    

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/Flang.cpp
    clang/lib/Driver/Types.cpp
    flang/test/Flang-Driver/driver-help-hidden.f90
    flang/test/Flang-Driver/driver-help.f90
    flang/test/Frontend/input-output-file.f90
    flang/test/Frontend/multiple-input-files.f90

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index ade330bd7ba4..bbaa16658639 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4236,11 +4236,17 @@ def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Optio
   MarshallingInfoString<LangOpts<"SYCLVersion">, "SYCL_None">, ShouldParseIf<fsycl.KeyPath>, AutoNormalizeEnum;
 
 //===----------------------------------------------------------------------===//
-// FlangOption and FC1 Options
+// FLangOption + CoreOption + NoXarchOption
 //===----------------------------------------------------------------------===//
-def test_io : Flag<["-"], "test-io">, Flags<[HelpHidden, FlangOption, FC1Option, FlangOnlyOption]>, Group<Action_Group>,
-  HelpText<"Run the InputOuputTest action. Use for development and testing only.">;
+let Flags = [FlangOption, FlangOnlyOption, NoXarchOption, CoreOption] in {
+def Xflang : Separate<["-"], "Xflang">,
+  HelpText<"Pass <arg> to the flang compiler">, MetaVarName<"<arg>">,
+  Flags<[NoXarchOption, CoreOption]>, Group<CompileOnly_Group>;
+}
 
+//===----------------------------------------------------------------------===//
+// FlangOption and FC1 Options
+//===----------------------------------------------------------------------===//
 let Flags = [FC1Option, FlangOption, FlangOnlyOption] in {
 
 def ffixed_form : Flag<["-"], "ffixed-form">, Group<f_Group>,
@@ -4270,7 +4276,6 @@ def fimplicit_none : Flag<["-"], "fimplicit-none">, Group<f_Group>,
 def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group<f_Group>;
 def falternative_parameter_statement : Flag<["-"], "falternative-parameter-statement">, Group<f_Group>,
   HelpText<"Enable the old style PARAMETER statement">;
-
 }
 
 //===----------------------------------------------------------------------===//
@@ -4278,6 +4283,8 @@ def falternative_parameter_statement : Flag<["-"], "falternative-parameter-state
 //===----------------------------------------------------------------------===//
 let Flags = [FC1Option, FlangOnlyOption] in {
 
+def test_io : Flag<["-"], "test-io">, Group<Action_Group>,
+  HelpText<"Run the InputOuputTest action. Use for development and testing only.">;
 def fdebug_unparse : Flag<["-"], "fdebug-unparse">, Group<Action_Group>,
   HelpText<"Unparse and stop.">;
 def fdebug_unparse_with_symbols : Flag<["-"], "fdebug-unparse-with-symbols">, Group<Action_Group>,

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 98d37eb7e692..b79b94a11956 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -63,9 +63,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   // CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
   if (isa<PreprocessJobAction>(JA)) {
-    if (C.getArgs().hasArg(options::OPT_test_io))
-      CmdArgs.push_back("-test-io");
-    else
       CmdArgs.push_back("-E");
   } else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) {
     if (JA.getType() == types::TY_Nothing) {
@@ -102,6 +99,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   // Add other compile options
   AddOtherOptions(Args, CmdArgs);
 
+  // Forward -Xflang arguments to -fc1
+  Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
+
   if (Output.isFilename()) {
     CmdArgs.push_back("-o");
     CmdArgs.push_back(Output.getFilename());

diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index e898334c3227..2050dffa6fa0 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -325,12 +325,10 @@ types::getCompilationPhases(const clang::driver::Driver &Driver,
   // Filter to compiler mode. When the compiler is run as a preprocessor then
   // compilation is not an option.
   // -S runs the compiler in Assembly listing mode.
-  // -test-io is used by Flang to run InputOutputTest action
   if (Driver.CCCIsCPP() || DAL.getLastArg(options::OPT_E) ||
       DAL.getLastArg(options::OPT__SLASH_EP) ||
       DAL.getLastArg(options::OPT_M, options::OPT_MM) ||
-      DAL.getLastArg(options::OPT__SLASH_P) ||
-      DAL.getLastArg(options::OPT_test_io))
+      DAL.getLastArg(options::OPT__SLASH_P))
     LastPhase = phases::Preprocess;
 
   // --precompile only runs up to precompilation.

diff  --git a/flang/test/Flang-Driver/driver-help-hidden.f90 b/flang/test/Flang-Driver/driver-help-hidden.f90
index b88062b22fde..a0d437cd0ac8 100644
--- a/flang/test/Flang-Driver/driver-help-hidden.f90
+++ b/flang/test/Flang-Driver/driver-help-hidden.f90
@@ -41,9 +41,9 @@
 ! CHECK-NEXT: -I <dir>               Add directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir <dir>      Put MODULE files in <dir>
 ! CHECK-NEXT: -o <file> Write output to <file>
-! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U <macro>             Undefine macro <macro>
 ! CHECK-NEXT: --version Print version information
+! CHECK-NEXT: -Xflang <arg>          Pass <arg> to the flang compiler
 
 !-------------------------------------------------------------
 ! EXPECTED OUTPUT FOR FLANG DRIVER (flang-new)

diff  --git a/flang/test/Flang-Driver/driver-help.f90 b/flang/test/Flang-Driver/driver-help.f90
index b4072c148157..f1a442e017e5 100644
--- a/flang/test/Flang-Driver/driver-help.f90
+++ b/flang/test/Flang-Driver/driver-help.f90
@@ -43,6 +43,7 @@
 ! HELP-NEXT: -o <file>              Write output to <file>
 ! HELP-NEXT: -U <macro>             Undefine macro <macro>
 ! HELP-NEXT: --version              Print version information
+! HELP-NEXT: -Xflang <arg>          Pass <arg> to the flang compiler
 
 !-------------------------------------------------------------
 ! EXPECTED OUTPUT FOR FLANG FRONTEND DRIVER (flang-new -fc1)
@@ -79,6 +80,7 @@
 ! HELP-FC1-NEXT: -I <dir>               Add directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir <dir>      Put MODULE files in <dir>
 ! HELP-FC1-NEXT: -o <file>              Write output to <file>
+! HELP-FC1-NEXT: -test-io               Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U <macro>             Undefine macro <macro>
 ! HELP-FC1-NEXT: --version              Print version information
 

diff  --git a/flang/test/Frontend/input-output-file.f90 b/flang/test/Frontend/input-output-file.f90
index 8964f163feb1..47983660f5ad 100644
--- a/flang/test/Frontend/input-output-file.f90
+++ b/flang/test/Frontend/input-output-file.f90
@@ -1,16 +1,18 @@
-! RUN: rm -rf %S/input-output-file.txt
-
 ! REQUIRES: new-flang-driver
 
 !--------------------------
 ! FLANG DRIVER (flang-new)
 !--------------------------
+! NOTE: Use `-E` so that the compiler driver stops after the 1st compilation phase, preprocessing. That's all we need.
+
 ! TEST 1: Print to stdout (implicit)
-! RUN: %flang-new -test-io %s  2>&1 | FileCheck %s --match-full-lines
+! RUN: %flang-new -E -Xflang -test-io %s  2>&1 | FileCheck %s --match-full-lines
+
 ! TEST 2: Print to stdout (explicit)
-! RUN: %flang-new -test-io -o - %s  2>&1 | FileCheck %s --match-full-lines
+! RUN: %flang-new -E -Xflang -test-io -o - %s  2>&1 | FileCheck %s --match-full-lines
+
 ! TEST 3: Print to a file
-! RUN: %flang-new -test-io -o %t %s 2>&1 && FileCheck %s --match-full-lines --input-file=%t
+! RUN: %flang-new -E -Xflang -test-io -o %t %s 2>&1 && FileCheck %s --match-full-lines --input-file=%t
 
 !----------------------------------------
 ! FLANG FRONTEND DRIVER (flang-new -fc1)
@@ -21,6 +23,7 @@
 ! RUN: rm -rf %t-dir && mkdir -p %t-dir && cd %t-dir
 ! RUN: cp %s .
 ! RUN: %flang-new -fc1 -test-io input-output-file.f90  2>&1 && FileCheck %s --match-full-lines --input-file=input-output-file.txt
+
 ! TEST 5: Write to a file (explicit)
 ! RUN: %flang-new -fc1 -test-io  -o %t %s 2>&1 && FileCheck %s --match-full-lines --input-file=%t
 

diff  --git a/flang/test/Frontend/multiple-input-files.f90 b/flang/test/Frontend/multiple-input-files.f90
index f1fb7d1caae3..f06461a6060b 100644
--- a/flang/test/Frontend/multiple-input-files.f90
+++ b/flang/test/Frontend/multiple-input-files.f90
@@ -1,16 +1,16 @@
-! RUN: rm -rf %S/multiple-input-files.txt  %S/Inputs/hello-world.txt
-
 ! REQUIRES: new-flang-driver
 
 !--------------------------
 ! FLANG DRIVER (flang-new)
 !--------------------------
+! NOTE: Use `-E` so that the compiler driver stops after the 1st compilation phase, preprocessing. That's all we need.
+
 ! TEST 1: Both input files are processed (output is printed to stdout)
-! RUN: %flang-new -test-io %s %S/Inputs/hello-world.f90 | FileCheck %s --match-full-lines -check-prefix=FLANG
+! RUN: %flang-new -E -Xflang -test-io %s %S/Inputs/hello-world.f90 | FileCheck %s --match-full-lines -check-prefix=FLANG
 
 ! TEST 2: None of the files is processed (not possible to specify the output file when multiple input files are present)
-! RUN: not %flang-new -test-io -o - %S/Inputs/hello-world.f90 %s  2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
-! RUN: not %flang-new -test-io -o %t %S/Inputs/hello-world.f90 %s 2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
+! RUN: not %flang-new -E -Xflang -test-io -o - %S/Inputs/hello-world.f90 %s  2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
+! RUN: not %flang-new -E -Xflang -test-io -o %t %S/Inputs/hello-world.f90 %s 2>&1 | FileCheck %s --match-full-lines -check-prefix=ERROR
 
 !----------------------------------------
 ! FLANG FRONTEND DRIVER (flang-new -fc1)


        


More information about the cfe-commits mailing list