diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4236,11 +4236,17 @@ MarshallingInfoString, "SYCL_None">, ShouldParseIf, AutoNormalizeEnum; //===----------------------------------------------------------------------===// -// FlangOption and FC1 Options +// FLangOption + CoreOption + NoXarchOption //===----------------------------------------------------------------------===// -def test_io : Flag<["-"], "test-io">, Flags<[HelpHidden, FlangOption, FC1Option, FlangOnlyOption]>, 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 to the flang compiler">, MetaVarName<"">, + Flags<[NoXarchOption, CoreOption]>, Group; +} +//===----------------------------------------------------------------------===// +// FlangOption and FC1 Options +//===----------------------------------------------------------------------===// let Flags = [FC1Option, FlangOption, FlangOnlyOption] in { def ffixed_form : Flag<["-"], "ffixed-form">, Group, @@ -4270,7 +4276,6 @@ def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group; def falternative_parameter_statement : Flag<["-"], "falternative-parameter-statement">, Group, HelpText<"Enable the old style PARAMETER statement">; - } //===----------------------------------------------------------------------===// @@ -4278,6 +4283,8 @@ //===----------------------------------------------------------------------===// let Flags = [FC1Option, FlangOnlyOption] in { +def test_io : Flag<["-"], "test-io">, Group, + HelpText<"Run the InputOuputTest action. Use for development and testing only.">; def fdebug_unparse : Flag<["-"], "fdebug-unparse">, Group, HelpText<"Unparse and stop.">; def fdebug_unparse_with_symbols : Flag<["-"], "fdebug-unparse-with-symbols">, Group, diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -63,9 +63,6 @@ // CmdArgs.push_back(Args.MakeArgString(TripleStr)); if (isa(JA)) { - if (C.getArgs().hasArg(options::OPT_test_io)) - CmdArgs.push_back("-test-io"); - else CmdArgs.push_back("-E"); } else if (isa(JA) || isa(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()); diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp --- a/clang/lib/Driver/Types.cpp +++ b/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. diff --git a/flang/test/Flang-Driver/driver-help-hidden.f90 b/flang/test/Flang-Driver/driver-help-hidden.f90 --- 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 Add directory to the end of the list of include search paths ! CHECK-NEXT: -module-dir Put MODULE files in ! CHECK-NEXT: -o Write output to -! CHECK-NEXT: -test-io Run the InputOuputTest action. Use for development and testing only. ! CHECK-NEXT: -U Undefine macro ! CHECK-NEXT: --version Print version information +! CHECK-NEXT: -Xflang Pass 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 --- a/flang/test/Flang-Driver/driver-help.f90 +++ b/flang/test/Flang-Driver/driver-help.f90 @@ -43,6 +43,7 @@ ! HELP-NEXT: -o Write output to ! HELP-NEXT: -U Undefine macro ! HELP-NEXT: --version Print version information +! HELP-NEXT: -Xflang Pass to the flang compiler !------------------------------------------------------------- ! EXPECTED OUTPUT FOR FLANG FRONTEND DRIVER (flang-new -fc1) @@ -79,6 +80,7 @@ ! HELP-FC1-NEXT: -I Add directory to the end of the list of include search paths ! HELP-FC1-NEXT: -module-dir Put MODULE files in ! HELP-FC1-NEXT: -o Write output to +! HELP-FC1-NEXT: -test-io Run the InputOuputTest action. Use for development and testing only. ! HELP-FC1-NEXT: -U Undefine 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 --- 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 --- 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)