diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -218,6 +218,9 @@ /// Name to use when invoking gcc/g++. std::string CCCGenericGCCName; + /// Name to use when invoking flang. + std::string FFCGenericFortranName; + /// Name of configuration file if used. std::string ConfigFile; @@ -310,6 +313,9 @@ /// Name to use when invoking gcc/g++. const std::string &getCCCGenericGCCName() const { return CCCGenericGCCName; } + /// Name to use when invoking flang. + const std::string &getFFCGenericFortranName() const { return FFCGenericFortranName; } + const std::string &getConfigFile() const { return ConfigFile; } const llvm::opt::OptTable &getOpts() const { return getDriverOptTable(); } 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 @@ -261,6 +261,8 @@ def ccc_gcc_name : Separate<["-"], "ccc-gcc-name">, InternalDriverOpt, HelpText<"Name for native GCC compiler">, MetaVarName<"">; +def fcc_fortran_name : Separate<["-"], "ffc-fortran-name">, InternalDriverOpt, + HelpText<"Name for native Fortran compiler">; class InternalDebugOpt : Group, Flags<[DriverOption, HelpHidden, CoreOption]>; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -128,8 +128,8 @@ CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false), CCGenDiagnostics(false), - TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc), - CheckInputsExist(true), GenReproducer(false), + TargetTriple(TargetTriple), CCCGenericGCCName(""), FFCGenericFortranName(""), + Saver(Alloc), CheckInputsExist(true), GenReproducer(false), SuppressMissingInputWarning(false) { // Provide a sane fallback if no VFS is specified. @@ -1085,6 +1085,10 @@ .Default(SaveTempsCwd); } + // Extract -ffc args. + if (const Arg *A = Args.getLastArg(options::OPT_fcc_fortran_name)) + FFCGenericFortranName = A->getValue(); + setLTOMode(Args); // Process -fembed-bitcode= flags. 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 @@ -11,7 +11,6 @@ #include "CommonArgs.h" #include "clang/Driver/Options.h" - #include using namespace clang::driver; @@ -69,7 +68,13 @@ CmdArgs.push_back(Input.getFilename()); const auto& D = C.getDriver(); - const char* Exec = Args.MakeArgString(D.GetProgramPath("flang", TC)); + const std::string &customFortranName = D.getFFCGenericFortranName(); + const char *FortranName; + if (!customFortranName.empty()) + FortranName = customFortranName.c_str(); + else FortranName = "flang"; + + const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(FortranName)); C.addCommand(std::make_unique(JA, *this, Exec, CmdArgs, Inputs)); } diff --git a/clang/test/Driver/flang/clang-driver-2-frontend01.f90 b/clang/test/Driver/flang/clang-driver-2-frontend01.f90 new file mode 100644 --- /dev/null +++ b/clang/test/Driver/flang/clang-driver-2-frontend01.f90 @@ -0,0 +1,18 @@ +! Check wich name of flang frontend is invoked by the driver + +! Driver name has clang, but the flag -ffc-fortran-name is passed by the driver. +! The flag has preference over any other name that the Driver may have. +! Therefore the driver invokes the FE given by the flag. + +! The invocations should begin with .tmp1 -fc1. +! ALL-LABEL: "{{[^"]*}}clang-driver-2-frontend01.f90.tmp1" "-fc1" + +! Copy clang to two temporary file +! t1 is the new frontend name. +! RUN: cp %clang %t1 +! RUN: %clang --driver-mode=flang -ffc-fortran-name %basename_t.tmp1 -### %s 2>&1 | FileCheck --check-prefixes=ALL,CHECK-EMIT-OBJ %s +! CHECK-EMIT-OBJ-DAG: "-emit-obj" +! CHECK-EMIT-OBJ-DAG: "-o" "{{[^"]*}}.o + +! Should end in the input file. +! ALL: "{{.*}}clang-driver-2-frontend01.f90"{{$}} diff --git a/clang/test/Driver/flang/driver-2-frontend01.f90 b/clang/test/Driver/flang/driver-2-frontend01.f90 new file mode 100644 --- /dev/null +++ b/clang/test/Driver/flang/driver-2-frontend01.f90 @@ -0,0 +1,18 @@ +! Check wich name of flang frontend is invoked by the driver + +! Driver name is a randon name. It does not contain flag, flang or clang, +! therefore the driver invokes flang FE. + +! The invocations should begin with flang -fc1. +! ALL-LABEL: "{{[^"]*}}flang" "-fc1" + +! Copy clang to two temporary file +! t1 is the new driver name. +! RUN: cp %clang %t1 +! RUN: %t1 --driver-mode=flang -### %s 2>&1 | FileCheck --check-prefixes=ALL,CHECK-EMIT-OBJ %s +! CHECK-EMIT-OBJ-DAG: "-emit-obj" +! CHECK-EMIT-OBJ-DAG: "-o" "{{[^"]*}}.o + +! Should end in the input file. +! ALL: "{{.*}}driver-2-frontend01.f90"{{$}} + diff --git a/clang/test/Driver/flang/driver-2-frontend02.f90 b/clang/test/Driver/flang/driver-2-frontend02.f90 new file mode 100644 --- /dev/null +++ b/clang/test/Driver/flang/driver-2-frontend02.f90 @@ -0,0 +1,19 @@ +! Check wich name of flang frontend is invoked by the driver + +! Driver name is a randon name. It does not contain flang or clang, +! but the driver gives a flag with the desired FE to be used. +! Therefore it should use the FE given by the flag. + +! The invocations should begin with .tmp2 -fc1. +! ALL-LABEL: "{{[^"]*}}driver-2-frontend02.f90.tmp2" "-fc1" + +! Copy clang to two temporary file. +! t1 is the driver name. t2 is the frontend name +! RUN: cp %clang %t1 +! RUN: cp %clang %t2 +! RUN: %t1 --driver-mode=flang -### -ffc-fortran-name %basename_t.tmp2 %s 2>&1 | FileCheck --check-prefixes=ALL,CHECK-EMIT-OBJ %s +! CHECK-EMIT-OBJ-DAG: "-emit-obj" +! CHECK-EMIT-OBJ-DAG: "-o" "{{[^"]*}}.o + +! Should end in the input file. +! ALL: "{{.*}}driver-2-frontend02.f90"{{$}} diff --git a/clang/test/Driver/flang/flang-driver-2-frontend01.f90 b/clang/test/Driver/flang/flang-driver-2-frontend01.f90 new file mode 100644 --- /dev/null +++ b/clang/test/Driver/flang/flang-driver-2-frontend01.f90 @@ -0,0 +1,16 @@ +! Check wich name of flang frontend is invoked by the driver + +! Driver name has flang, therefore the Driver invokes FE +! with the same name as the driver. + +! The invocations should begin with .tmp1 -fc1. +! ALL-LABEL: "{{[^"]*}}flang" "-fc1" + +! Copy clang to a temporary file to be the driver name +! RUN: cp %clang %t1 +! RUN: %t1 --driver-mode=flang -### %s 2>&1 | FileCheck --check-prefixes=ALL,CHECK-EMIT-OBJ %s +! CHECK-EMIT-OBJ-DAG: "-emit-obj" +! CHECK-EMIT-OBJ-DAG: "-o" "{{[^"]*}}.o + +! Should end in the input file. +! ALL: "{{.*}}flang-driver-2-frontend01.f90"{{$}} diff --git a/clang/test/Driver/flang/flang-driver-2-frontend02.f90 b/clang/test/Driver/flang/flang-driver-2-frontend02.f90 new file mode 100644 --- /dev/null +++ b/clang/test/Driver/flang/flang-driver-2-frontend02.f90 @@ -0,0 +1,19 @@ +! Check wich name of flang frontend is invoked by the driver + +! Driver name has flang, but the flag -ffc-fortran-name is passed by the driver. +! The flag has preference over any other name that the Driver may have. +! Therefore the driver invokes the FE given by the flag. + +! The invocations should begin with .tmp2 -fc1. +! ALL-LABEL: "{{[^"]*}}flang-driver-2-frontend02.f90.tmp2" "-fc1" + +! Copy clang to two temporary file. +! t1 is the driver name. %t2 is the frontend name +! RUN: cp %clang %t1 +! RUN: cp %clang %t2 +! RUN: %t1 --driver-mode=flang -ffc-fortran-name %basename_t.tmp2 -### %s 2>&1 | FileCheck --check-prefixes=ALL,CHECK-EMIT-OBJ %s +! CHECK-EMIT-OBJ-DAG: "-emit-obj" +! CHECK-EMIT-OBJ-DAG: "-o" "{{[^"]*}}.o + +! Should end in the input file. +! ALL: "{{.*}}flang-driver-2-frontend02.f90"{{$}}