[Lldb-commits] [lldb] 4857b6f - Revert "Store OptTable::Info::Name as a StringRef"
Douglas Yung via lldb-commits
lldb-commits at lists.llvm.org
Tue Dec 6 19:37:59 PST 2022
Author: Douglas Yung
Date: 2022-12-06T19:37:05-08:00
New Revision: 4857b6f8fff614c89ed35031c298df81394459af
URL: https://github.com/llvm/llvm-project/commit/4857b6f8fff614c89ed35031c298df81394459af
DIFF: https://github.com/llvm/llvm-project/commit/4857b6f8fff614c89ed35031c298df81394459af.diff
LOG: Revert "Store OptTable::Info::Name as a StringRef"
This reverts commit 5951b0bb23f3265bea16f28c2af9d278b9d829c6.
This is causing 24 test failures on the PS4 linux bot: https://lab.llvm.org/buildbot/#/builders/139/builds/32263
Added:
Modified:
clang/lib/Driver/ToolChains/Gnu.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
llvm/include/llvm/ADT/StringRef.h
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/utils/TableGen/OptParserEmitter.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 60d62e2b9c5c1..4621850f13772 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -331,8 +331,8 @@ static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) {
if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
const Driver &D = TC.getDriver();
const llvm::opt::OptTable &Opts = D.getOpts();
- StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
- StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
+ const char *StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
+ const char *NoPIEName = Opts.getOptionName(options::OPT_nopie);
D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
}
return HasStaticPIE;
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index fde098840be4b..9d89148616be1 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1055,7 +1055,7 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
// Only add the version-min options if we got a version from somewhere
if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
#define OPTION(PREFIX, NAME, VAR, ...) \
- llvm::StringRef opt_##VAR = NAME; \
+ const char *opt_##VAR = NAME; \
(void)opt_##VAR;
#include "clang/Driver/Options.inc"
#undef OPTION
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 9fea390c2ed32..032f42a51ec0b 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -561,8 +561,7 @@ namespace llvm {
/// \param N The number of characters to included in the substring. If N
/// exceeds the number of characters remaining in the string, the string
/// suffix (starting with \p Start) will be returned.
- [[nodiscard]] constexpr StringRef substr(size_t Start,
- size_t N = npos) const {
+ [[nodiscard]] StringRef substr(size_t Start, size_t N = npos) const {
Start = std::min(Start, Length);
return StringRef(Data + Start, std::min(N, Length - Start));
}
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index e884ebeb788c4..07d9870f71b33 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -44,7 +44,7 @@ class OptTable {
/// A null terminated array of prefix strings to apply to name while
/// matching.
const char *const *Prefixes;
- StringRef Name;
+ const char *Name;
const char *HelpText;
const char *MetaVar;
unsigned ID;
@@ -102,7 +102,9 @@ class OptTable {
const Option getOption(OptSpecifier Opt) const;
/// Lookup the name of the given option.
- StringRef getOptionName(OptSpecifier id) const { return getInfo(id).Name; }
+ const char *getOptionName(OptSpecifier id) const {
+ return getInfo(id).Name;
+ }
/// Get the kind of the given option.
unsigned getOptionKind(OptSpecifier id) const {
@@ -182,7 +184,7 @@ class OptTable {
/// takes
///
/// \return true in success, and false in fail.
- bool addValues(StringRef Option, const char *Values);
+ bool addValues(const char *Option, const char *Values);
/// Parse a single argument; returning the new argument and
/// updating Index.
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index f23561b5d078d..ef4873eb7f9c4 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -36,23 +36,31 @@ namespace opt {
// Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
// with an exception. '\0' comes at the end of the alphabet instead of the
// beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
- size_t MinSize = std::min(A.size(), B.size());
- if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
- return Res;
+static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
+ const char *X = A, *Y = B;
+ char a = tolower(*A), b = tolower(*B);
+ while (a == b) {
+ if (a == '\0')
+ return 0;
+
+ a = tolower(*++X);
+ b = tolower(*++Y);
+ }
- if (A.size() == B.size())
- return 0;
+ if (a == '\0') // A is a prefix of B.
+ return 1;
+ if (b == '\0') // B is a prefix of A.
+ return -1;
- return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
- : -1 /* B is a prefix of A */;
+ // Otherwise lexicographic.
+ return (a < b) ? -1 : 1;
}
#ifndef NDEBUG
-static int StrCmpOptionName(StringRef A, StringRef B) {
+static int StrCmpOptionName(const char *A, const char *B) {
if (int N = StrCmpOptionNameIgnoreCase(A, B))
return N;
- return A.compare(B);
+ return strcmp(A, B);
}
static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
@@ -78,7 +86,7 @@ static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
#endif
// Support lower_bound between info and an option name.
-static inline bool operator<(const OptTable::Info &I, StringRef Name) {
+static inline bool operator<(const OptTable::Info &I, const char *Name) {
return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
}
@@ -313,7 +321,7 @@ unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
return BestDistance;
}
-bool OptTable::addValues(StringRef Option, const char *Values) {
+bool OptTable::addValues(const char *Option, const char *Values) {
for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
Info &In = OptionInfos[I];
if (optionMatches(In, Option)) {
@@ -339,8 +347,8 @@ std::unique_ptr<Arg> OptTable::parseOneArgGrouped(InputArgList &Args,
const Info *End = OptionInfos.data() + OptionInfos.size();
StringRef Name = Str.ltrim(PrefixChars);
- const Info *Start =
- std::lower_bound(OptionInfos.data() + FirstSearchableIndex, End, Name);
+ const Info *Start = std::lower_bound(
+ OptionInfos.data() + FirstSearchableIndex, End, Name.data());
const Info *Fallback = nullptr;
unsigned Prev = Index;
@@ -407,7 +415,7 @@ std::unique_ptr<Arg> OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
StringRef Name = StringRef(Str).ltrim(PrefixChars);
// Search for the first next option which could be a prefix.
- Start = std::lower_bound(Start, End, Name);
+ Start = std::lower_bound(Start, End, Name.data());
// Options are stored in sorted order, with '\0' at the end of the
// alphabet. Since the only options which can accept a string must
diff --git a/llvm/unittests/Option/OptionMarshallingTest.cpp b/llvm/unittests/Option/OptionMarshallingTest.cpp
index c4d48acc7a3f9..85f0d86a86968 100644
--- a/llvm/unittests/Option/OptionMarshallingTest.cpp
+++ b/llvm/unittests/Option/OptionMarshallingTest.cpp
@@ -6,11 +6,10 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/StringRef.h"
#include "gtest/gtest.h"
struct OptionWithMarshallingInfo {
- llvm::StringRef Name;
+ const char *Name;
const char *KeyPath;
const char *ImpliedCheck;
const char *ImpliedValue;
@@ -28,10 +27,10 @@ static const OptionWithMarshallingInfo MarshallingTable[] = {
};
TEST(OptionMarshalling, EmittedOrderSameAsDefinitionOrder) {
- ASSERT_STREQ(MarshallingTable[0].Name.data(), "marshalled-flag-d");
- ASSERT_STREQ(MarshallingTable[1].Name.data(), "marshalled-flag-c");
- ASSERT_STREQ(MarshallingTable[2].Name.data(), "marshalled-flag-b");
- ASSERT_STREQ(MarshallingTable[3].Name.data(), "marshalled-flag-a");
+ ASSERT_STREQ(MarshallingTable[0].Name, "marshalled-flag-d");
+ ASSERT_STREQ(MarshallingTable[1].Name, "marshalled-flag-c");
+ ASSERT_STREQ(MarshallingTable[2].Name, "marshalled-flag-b");
+ ASSERT_STREQ(MarshallingTable[3].Name, "marshalled-flag-a");
}
TEST(OptionMarshalling, EmittedSpecifiedKeyPath) {
diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp
index ebef5847f7137..717a994c219c5 100644
--- a/llvm/utils/TableGen/OptParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptParserEmitter.cpp
@@ -54,9 +54,9 @@ static std::string getOptionSpelling(const Record &R) {
static void emitNameUsingSpelling(raw_ostream &OS, const Record &R) {
size_t PrefixLength;
- OS << "llvm::StringRef(";
+ OS << "&";
write_cstring(OS, StringRef(getOptionSpelling(R, PrefixLength)));
- OS << ").substr(" << PrefixLength << ")";
+ OS << "[" << PrefixLength << "]";
}
class MarshallingInfo {
More information about the lldb-commits
mailing list