[clang] e1cad42 - [X86] Make getX86TargetCPU return std::string instead of const char *. Remove call to MakeArgString. NFCI

Craig Topper via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 6 13:18:41 PDT 2020


Author: Craig Topper
Date: 2020-08-06T13:18:15-07:00
New Revision: e1cad4234cf3a3d0747c140e135e413ece22cf63

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

LOG: [X86] Make getX86TargetCPU return std::string instead of const char *. Remove call to MakeArgString. NFCI

I believe this function used to be called directly from X86
specific code and was used to immediately create -target-cpu
command line. A later refactoring changed it to to be called from
a generic getCPU function that returns std::string. So on some
paths we created a string using MakeArgString converted that to
std::string then called MakeArgString again from that.

Instead just return std::string directly like the other targets.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Arch/X86.cpp
    clang/lib/Driver/ToolChains/Arch/X86.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index 2cc44c09917f..5d9a7234b027 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -20,7 +20,7 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-const char *x86::getX86TargetCPU(const ArgList &Args,
+std::string x86::getX86TargetCPU(const ArgList &Args,
                                  const llvm::Triple &Triple) {
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
     if (StringRef(A->getValue()) != "native")
@@ -33,7 +33,7 @@ const char *x86::getX86TargetCPU(const ArgList &Args,
     // with -native.
     std::string CPU = std::string(llvm::sys::getHostCPUName());
     if (!CPU.empty() && CPU != "generic")
-      return Args.MakeArgString(CPU);
+      return CPU;
   }
 
   if (const Arg *A = Args.getLastArgNoClaim(options::OPT__SLASH_arch)) {
@@ -64,7 +64,7 @@ const char *x86::getX86TargetCPU(const ArgList &Args,
   // Select the default CPU if none was given (or detection failed).
 
   if (!Triple.isX86())
-    return nullptr; // This routine is only handling x86 targets.
+    return ""; // This routine is only handling x86 targets.
 
   bool Is64Bit = Triple.getArch() == llvm::Triple::x86_64;
 

diff  --git a/clang/lib/Driver/ToolChains/Arch/X86.h b/clang/lib/Driver/ToolChains/Arch/X86.h
index 9f9c2b8c4b49..14f0a26c8be4 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.h
+++ b/clang/lib/Driver/ToolChains/Arch/X86.h
@@ -21,7 +21,7 @@ namespace driver {
 namespace tools {
 namespace x86 {
 
-const char *getX86TargetCPU(const llvm::opt::ArgList &Args,
+std::string getX86TargetCPU(const llvm::opt::ArgList &Args,
                             const llvm::Triple &Triple);
 
 void getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,


        


More information about the cfe-commits mailing list