TLI: Factor out sanitizeFunctionName. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231034 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Zolotukhin 2015-03-02 23:24:40 +00:00
parent 0b08b96fdd
commit a6f1fd6465

View File

@ -714,20 +714,28 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&
return *this;
}
bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
LibFunc::Func &F) const {
const char **Start = &StandardNames[0];
const char **End = &StandardNames[LibFunc::NumLibFuncs];
static StringRef sanitizeFunctionName(StringRef funcName) {
// Filter out empty names and names containing null bytes, those can't be in
// our table.
if (funcName.empty() || funcName.find('\0') != StringRef::npos)
return false;
return StringRef();
// Check for \01 prefix that is used to mangle __asm declarations and
// strip it if present.
if (funcName.front() == '\01')
funcName = funcName.substr(1);
return funcName;
}
bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
LibFunc::Func &F) const {
const char **Start = &StandardNames[0];
const char **End = &StandardNames[LibFunc::NumLibFuncs];
funcName = sanitizeFunctionName(funcName);
if (funcName.empty())
return false;
const char **I = std::lower_bound(
Start, End, funcName, [](const char *LHS, StringRef RHS) {
return std::strncmp(LHS, RHS.data(), RHS.size()) < 0;