awarzynski created this revision. Herald added a reviewer: sscalpone. Herald added subscribers: jansvoboda11, dang. awarzynski requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96864 Files: 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
Index: flang/test/Frontend/multiple-input-files.f90 =================================================================== --- flang/test/Frontend/multiple-input-files.f90 +++ flang/test/Frontend/multiple-input-files.f90 @@ -1,16 +1,15 @@ -! RUN: rm -rf %S/multiple-input-files.txt %S/Inputs/hello-world.txt - ! REQUIRES: new-flang-driver !-------------------------- ! FLANG DRIVER (flang-new) !-------------------------- +! NOTE: We need `-E` below in order to instruct the compiler driver to create a job representing a fronted compiler invocation ! 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) Index: flang/test/Frontend/input-output-file.f90 =================================================================== --- flang/test/Frontend/input-output-file.f90 +++ flang/test/Frontend/input-output-file.f90 @@ -1,16 +1,15 @@ -! RUN: rm -rf %S/input-output-file.txt - ! REQUIRES: new-flang-driver !-------------------------- ! FLANG DRIVER (flang-new) !-------------------------- +! NOTE: We need `-E` below in order to instruct the compiler driver to create a job representing a fronted compiler invocation ! 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) Index: flang/test/Flang-Driver/driver-help.f90 =================================================================== --- flang/test/Flang-Driver/driver-help.f90 +++ 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) @@ -73,6 +74,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 Index: flang/test/Flang-Driver/driver-help-hidden.f90 =================================================================== --- flang/test/Flang-Driver/driver-help-hidden.f90 +++ 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) Index: clang/lib/Driver/Types.cpp =================================================================== --- clang/lib/Driver/Types.cpp +++ clang/lib/Driver/Types.cpp @@ -325,12 +325,10 @@ // 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. Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -63,9 +63,6 @@ // 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 @@ // 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()); Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -4222,11 +4222,17 @@ 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>, @@ -4256,7 +4262,6 @@ 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">; - } //===----------------------------------------------------------------------===// @@ -4264,6 +4269,8 @@ //===----------------------------------------------------------------------===// 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>,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits