diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 00df8a4f5596..cfe8ae74ffaf 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -933,7 +933,7 @@ template void BinaryFile::parse() { // characters in a filename are replaced with underscore. std::string S = "_binary_" + MB.getBufferIdentifier().str(); for (size_t I = 0; I < S.size(); ++I) - if (!elf::isAlnum(S[I])) + if (!isAlnum(S[I])) S[I] = '_'; Symtab->addRegular(Saver.save(S + "_start"), STV_DEFAULT, STT_OBJECT, diff --git a/lld/ELF/Strings.cpp b/lld/ELF/Strings.cpp index 923aad57b868..766258f00ccd 100644 --- a/lld/ELF/Strings.cpp +++ b/lld/ELF/Strings.cpp @@ -54,18 +54,11 @@ std::vector elf::parseHex(StringRef S) { return Hex; } -static bool isAlpha(char C) { - return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z') || C == '_'; -} - -// Returns true if C is a valid letter, digit or underscore as defined in the -// "C" locale. -bool elf::isAlnum(char C) { return isAlpha(C) || ('0' <= C && C <= '9'); } - // Returns true if S is valid as a C language identifier. bool elf::isValidCIdentifier(StringRef S) { - return !S.empty() && isAlpha(S[0]) && - std::all_of(S.begin() + 1, S.end(), isAlnum); + return !S.empty() && (isAlpha(S[0]) || S[0] == '_') && + std::all_of(S.begin() + 1, S.end(), + [](char C) { return C == '_' || isAlnum(C); }); } // Returns the demangled C++ symbol name for Name. diff --git a/lld/ELF/Strings.h b/lld/ELF/Strings.h index aef9a92c0134..3c7e7445af16 100644 --- a/lld/ELF/Strings.h +++ b/lld/ELF/Strings.h @@ -22,7 +22,6 @@ namespace lld { namespace elf { std::vector parseHex(StringRef S); -bool isAlnum(char C); bool isValidCIdentifier(StringRef S); // This is a lazy version of StringRef. String size is computed lazily