diff --git a/llvm/include/llvm/MC/TargetRegistry.h b/llvm/include/llvm/MC/TargetRegistry.h --- a/llvm/include/llvm/MC/TargetRegistry.h +++ b/llvm/include/llvm/MC/TargetRegistry.h @@ -791,8 +791,7 @@ /// \param Triple - The triple to use for finding a target. /// \param Error - On failure, an error string describing why no target was /// found. - static const Target *lookupTarget(const std::string &Triple, - std::string &Error); + static const Target *lookupTarget(StringRef Triple, std::string &Error); /// lookupTarget - Lookup a target based on an architecture name /// and a target triple. If the architecture name is non-empty, @@ -805,8 +804,8 @@ /// by architecture is done. /// \param Error - On failure, an error string describing why no target was /// found. - static const Target *lookupTarget(const std::string &ArchName, - Triple &TheTriple, std::string &Error); + static const Target *lookupTarget(StringRef ArchName, Triple &TheTriple, + std::string &Error); /// @} /// @name Target Registration diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp --- a/llvm/lib/MC/TargetRegistry.cpp +++ b/llvm/lib/MC/TargetRegistry.cpp @@ -21,7 +21,7 @@ return make_range(iterator(FirstTarget), iterator()); } -const Target *TargetRegistry::lookupTarget(const std::string &ArchName, +const Target *TargetRegistry::lookupTarget(StringRef ArchName, Triple &TheTriple, std::string &Error) { // Allocate target machine. First, check whether the user has explicitly @@ -33,7 +33,7 @@ [&](const Target &T) { return ArchName == T.getName(); }); if (I == targets().end()) { - Error = "invalid target '" + ArchName + "'.\n"; + Error = ("invalid target '" + ArchName + "'.\n").str(); return nullptr; } @@ -59,8 +59,7 @@ return TheTarget; } -const Target *TargetRegistry::lookupTarget(const std::string &TT, - std::string &Error) { +const Target *TargetRegistry::lookupTarget(StringRef TT, std::string &Error) { // Provide special warning when no targets are initialized. if (targets().begin() == targets().end()) { Error = "Unable to find target for this triple (no targets are registered)"; @@ -71,7 +70,8 @@ auto I = find_if(targets(), ArchMatch); if (I == targets().end()) { - Error = "No available targets are compatible with triple \"" + TT + "\""; + Error = ("No available targets are compatible with triple \"" + TT + "\"") + .str(); return nullptr; }