CarolineConcatto updated this revision to Diff 261806.
CarolineConcatto marked 7 inline comments as done.
CarolineConcatto added a comment.

Rename the flag and fix reviews comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73951/new/

https://reviews.llvm.org/D73951

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/test/Driver/flang/custom_frontend_flang.f90

Index: clang/test/Driver/flang/custom_frontend_flang.f90
===================================================================
--- /dev/null
+++ clang/test/Driver/flang/custom_frontend_flang.f90
@@ -0,0 +1,10 @@
+! Check wich compiler's name for fortran should be invoked.
+
+! The flag -cfc-flang-name is passed by the driver.
+! The flag has preference over "flang" compiler.
+! Therefore the driver invokes the compiler given by the flag.
+
+! RUN: %clang --driver-mode=flang -cfc-flang-name alternative_fortran_compiler -### %s 2>&1 | FileCheck %s
+
+! The invocations should be with alternative_fortran_compiler -fc1.
+! CHECK: "{{[^"]*}}alternative_fortran_compiler" "-fc1"
Index: clang/lib/Driver/ToolChains/Flang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -11,7 +11,6 @@
 #include "CommonArgs.h"
 
 #include "clang/Driver/Options.h"
-
 #include <cassert>
 
 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 &customFlangName = D.getCFCGenericFlangName();
+  const char *FlangName;
+  if (!customFlangName.empty())
+    FlangName = customFlangName.c_str();
+  else FlangName = "flang";
+
+  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(FlangName));
   C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
 }
 
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -129,8 +129,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(""), CFCGenericFlangName(""),
+      Saver(Alloc), CheckInputsExist(true), GenReproducer(false),
       SuppressMissingInputWarning(false) {
   // Provide a sane fallback if no VFS is specified.
   if (!this->VFS)
@@ -1089,6 +1089,10 @@
                     .Default(SaveTempsCwd);
   }
 
+  // Extract -cfc arg.
+  if (const Arg *A = Args.getLastArg(options::OPT_cfc_flang_name))
+    CFCGenericFlangName = A->getValue();
+
   setLTOMode(Args);
 
   // Process -fembed-bitcode= flags.
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -264,6 +264,8 @@
 def ccc_gcc_name : Separate<["-"], "ccc-gcc-name">, InternalDriverOpt,
   HelpText<"Name for native GCC compiler">,
   MetaVarName<"<gcc-path>">;
+def cfc_flang_name : Separate<["-"], "cfc-flang-name">, InternalDriverOpt,
+  HelpText<"Name for a custom fortran compiler(cfc) for flang">;
 
 class InternalDebugOpt : Group<internal_debug_Group>,
   Flags<[DriverOption, HelpHidden, CoreOption]>;
Index: clang/include/clang/Driver/Driver.h
===================================================================
--- clang/include/clang/Driver/Driver.h
+++ 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 a custom fortran compiler.
+  std::string CFCGenericFlangName;
+
   /// 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 a custom fortran compiler.
+  const std::string &getCFCGenericFlangName() const { return CFCGenericFlangName; }
+
   const std::string &getConfigFile() const { return ConfigFile; }
 
   const llvm::opt::OptTable &getOpts() const { return getDriverOptTable(); }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to