diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2024-12-13 23:58:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-13 23:58:48 -0800 |
commit | ca79ff07d8ae7a0c2531bfdb1cb623e25e5bd486 (patch) | |
tree | f6a13832bb6b9a8638a11ca82774dd43a62aab1d /clang/lib/Basic/Builtins.cpp | |
parent | 2291e5aa45dc135a5f908032eb31d19ef3570114 (diff) | |
download | llvm-ca79ff07d8ae7a0c2531bfdb1cb623e25e5bd486.zip llvm-ca79ff07d8ae7a0c2531bfdb1cb623e25e5bd486.tar.gz llvm-ca79ff07d8ae7a0c2531bfdb1cb623e25e5bd486.tar.bz2 |
Revert "Switch builtin strings to use string tables" (#119638)
Reverts llvm/llvm-project#118734
There are currently some specific versions of MSVC that are miscompiling
this code (we think). We don't know why as all the other build bots and
at least some folks' local Windows builds work fine.
This is a candidate revert to help the relevant folks catch their
builders up and have time to debug the issue. However, the expectation
is to roll forward at some point with a workaround if at all possible.
Diffstat (limited to 'clang/lib/Basic/Builtins.cpp')
-rw-r--r-- | clang/lib/Basic/Builtins.cpp | 120 |
1 files changed, 39 insertions, 81 deletions
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index c991139..8dd1888 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -29,93 +29,54 @@ const char *HeaderDesc::getName() const { llvm_unreachable("Unknown HeaderDesc::HeaderID enum"); } -static constexpr auto BuiltinStorage = - Builtin::Storage<Builtin::FirstTSBuiltin>::Make( - CLANG_BUILTIN_STR_TABLE("not a builtin function", "", "") -#define BUILTIN CLANG_BUILTIN_STR_TABLE +static constexpr Builtin::Info BuiltinInfo[] = { + {"not a builtin function", nullptr, nullptr, nullptr, HeaderDesc::NO_HEADER, + ALL_LANGUAGES}, +#define BUILTIN(ID, TYPE, ATTRS) \ + {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES}, +#define LANGBUILTIN(ID, TYPE, ATTRS, LANGS) \ + {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, LANGS}, +#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, LANGS) \ + {#ID, TYPE, ATTRS, nullptr, HeaderDesc::HEADER, LANGS}, #include "clang/Basic/Builtins.inc" - , - {CLANG_BUILTIN_ENTRY("not a builtin function", "", "") -#define BUILTIN CLANG_BUILTIN_ENTRY -#define LANGBUILTIN CLANG_LANGBUILTIN_ENTRY -#define LIBBUILTIN CLANG_LIBBUILTIN_ENTRY -#include "clang/Basic/Builtins.inc" - }); +}; -std::pair<const char *, const Builtin::Info &> -Builtin::Context::getStrTableAndInfo(unsigned ID) const { +const Builtin::Info &Builtin::Context::getRecord(unsigned ID) const { if (ID < Builtin::FirstTSBuiltin) - return {BuiltinStorage.StringTable, BuiltinStorage.Infos[ID]}; - assert( - ((ID - Builtin::FirstTSBuiltin) < (TSInfos.size() + AuxTSInfos.size())) && - "Invalid builtin ID!"); + return BuiltinInfo[ID]; + assert(((ID - Builtin::FirstTSBuiltin) < + (TSRecords.size() + AuxTSRecords.size())) && + "Invalid builtin ID!"); if (isAuxBuiltinID(ID)) - return {AuxTSStrTable, - AuxTSInfos[getAuxBuiltinID(ID) - Builtin::FirstTSBuiltin]}; - return {TSStrTable, TSInfos[ID - Builtin::FirstTSBuiltin]}; -} - -static llvm::StringRef getStrFromTable(const char *StrTable, int Offset) { - return &StrTable[Offset]; -} - -/// Return the identifier name for the specified builtin, -/// e.g. "__builtin_abs". -llvm::StringRef Builtin::Context::getName(unsigned ID) const { - const auto &[StrTable, I] = getStrTableAndInfo(ID); - return getStrFromTable(StrTable, I.Offsets.Name); -} - -const char *Builtin::Context::getTypeString(unsigned ID) const { - const auto &[StrTable, I] = getStrTableAndInfo(ID); - return getStrFromTable(StrTable, I.Offsets.Type).data(); -} - -const char *Builtin::Context::getAttributesString(unsigned ID) const { - const auto &[StrTable, I] = getStrTableAndInfo(ID); - return getStrFromTable(StrTable, I.Offsets.Attributes).data(); -} - -const char *Builtin::Context::getRequiredFeatures(unsigned ID) const { - const auto &[StrTable, I] = getStrTableAndInfo(ID); - return getStrFromTable(StrTable, I.Offsets.Features).data(); + return AuxTSRecords[getAuxBuiltinID(ID) - Builtin::FirstTSBuiltin]; + return TSRecords[ID - Builtin::FirstTSBuiltin]; } void Builtin::Context::InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget) { - assert(TSStrTable == nullptr && "Already initialized target?"); - assert(TSInfos.empty() && "Already initialized target?"); - std::tie(TSStrTable, TSInfos) = Target.getTargetBuiltinStorage(); - if (AuxTarget) { - std::tie(AuxTSStrTable, AuxTSInfos) = AuxTarget->getTargetBuiltinStorage(); - } + assert(TSRecords.empty() && "Already initialized target?"); + TSRecords = Target.getTargetBuiltins(); + if (AuxTarget) + AuxTSRecords = AuxTarget->getTargetBuiltins(); } bool Builtin::Context::isBuiltinFunc(llvm::StringRef FuncName) { bool InStdNamespace = FuncName.consume_front("std-"); - const char *StrTable = BuiltinStorage.StringTable; for (unsigned i = Builtin::NotBuiltin + 1; i != Builtin::FirstTSBuiltin; ++i) { - const auto &I = BuiltinStorage.Infos[i]; - if (FuncName == getStrFromTable(StrTable, I.Offsets.Name) && - (bool)strchr(getStrFromTable(StrTable, I.Offsets.Attributes).data(), - 'z') == InStdNamespace) - return strchr(getStrFromTable(StrTable, I.Offsets.Attributes).data(), - 'f') != nullptr; + if (FuncName == BuiltinInfo[i].Name && + (bool)strchr(BuiltinInfo[i].Attributes, 'z') == InStdNamespace) + return strchr(BuiltinInfo[i].Attributes, 'f') != nullptr; } return false; } /// Is this builtin supported according to the given language options? -static bool builtinIsSupported(const char *StrTable, - const Builtin::Info &BuiltinInfo, +static bool builtinIsSupported(const Builtin::Info &BuiltinInfo, const LangOptions &LangOpts) { - auto AttributesStr = - getStrFromTable(StrTable, BuiltinInfo.Offsets.Attributes); - /* Builtins Unsupported */ - if (LangOpts.NoBuiltin && strchr(AttributesStr.data(), 'f') != nullptr) + if (LangOpts.NoBuiltin && strchr(BuiltinInfo.Attributes, 'f') != nullptr) return false; /* CorBuiltins Unsupported */ if (!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG)) @@ -162,7 +123,7 @@ static bool builtinIsSupported(const char *StrTable, if (!LangOpts.CPlusPlus && BuiltinInfo.Langs == CXX_LANG) return false; /* consteval Unsupported */ - if (!LangOpts.CPlusPlus20 && strchr(AttributesStr.data(), 'G') != nullptr) + if (!LangOpts.CPlusPlus20 && strchr(BuiltinInfo.Attributes, 'G') != nullptr) return false; return true; } @@ -173,23 +134,20 @@ static bool builtinIsSupported(const char *StrTable, void Builtin::Context::initializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts) { // Step #1: mark all target-independent builtins with their ID's. - for (const auto &&[Index, I] : - llvm::enumerate(llvm::ArrayRef(BuiltinStorage.Infos).drop_front())) - if (builtinIsSupported(BuiltinStorage.StringTable, I, LangOpts)) { - Table.get(getStrFromTable(BuiltinStorage.StringTable, I.Offsets.Name)) - .setBuiltinID(Index + 1); + for (unsigned i = Builtin::NotBuiltin + 1; i != Builtin::FirstTSBuiltin; ++i) + if (builtinIsSupported(BuiltinInfo[i], LangOpts)) { + Table.get(BuiltinInfo[i].Name).setBuiltinID(i); } // Step #2: Register target-specific builtins. - for (const auto &&[Index, I] : llvm::enumerate(TSInfos)) - if (builtinIsSupported(TSStrTable, I, LangOpts)) - Table.get(getStrFromTable(TSStrTable, I.Offsets.Name)) - .setBuiltinID(Index + Builtin::FirstTSBuiltin); + for (unsigned i = 0, e = TSRecords.size(); i != e; ++i) + if (builtinIsSupported(TSRecords[i], LangOpts)) + Table.get(TSRecords[i].Name).setBuiltinID(i + Builtin::FirstTSBuiltin); // Step #3: Register target-specific builtins for AuxTarget. - for (const auto &&[Index, I] : llvm::enumerate(AuxTSInfos)) - Table.get(getStrFromTable(AuxTSStrTable, I.Offsets.Name)) - .setBuiltinID(Index + Builtin::FirstTSBuiltin + TSInfos.size()); + for (unsigned i = 0, e = AuxTSRecords.size(); i != e; ++i) + Table.get(AuxTSRecords[i].Name) + .setBuiltinID(i + Builtin::FirstTSBuiltin + TSRecords.size()); // Step #4: Unregister any builtins specified by -fno-builtin-foo. for (llvm::StringRef Name : LangOpts.NoBuiltinFuncs) { @@ -206,7 +164,7 @@ void Builtin::Context::initializeBuiltins(IdentifierTable &Table, } unsigned Builtin::Context::getRequiredVectorWidth(unsigned ID) const { - const char *WidthPos = ::strchr(getAttributesString(ID), 'V'); + const char *WidthPos = ::strchr(getRecord(ID).Attributes, 'V'); if (!WidthPos) return 0; @@ -229,7 +187,7 @@ bool Builtin::Context::isLike(unsigned ID, unsigned &FormatIdx, assert(::toupper(Fmt[0]) == Fmt[1] && "Format string is not in the form \"xX\""); - const char *Like = ::strpbrk(getAttributesString(ID), Fmt); + const char *Like = ::strpbrk(getRecord(ID).Attributes, Fmt); if (!Like) return false; @@ -256,7 +214,7 @@ bool Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx, bool Builtin::Context::performsCallback(unsigned ID, SmallVectorImpl<int> &Encoding) const { - const char *CalleePos = ::strchr(getAttributesString(ID), 'C'); + const char *CalleePos = ::strchr(getRecord(ID).Attributes, 'C'); if (!CalleePos) return false; |