Use value_or instead of getValueOr. NFC

This commit is contained in:
Fangrui Song 2022-06-29 21:55:02 -07:00
parent a3ec54c660
commit 67854f9ed0
9 changed files with 15 additions and 17 deletions

View File

@ -42,7 +42,7 @@ public:
FS, FreshTime,
[&](llvm::Optional<llvm::StringRef> Data) {
GotParse = true;
Value = Data.getValueOr("").str();
Value = Data.value_or("").str();
},
[&]() {
GotRead = true;

View File

@ -38,7 +38,7 @@ json::Object encodeError(Error E) {
Error decodeError(const json::Object &O) {
std::string Msg =
std::string(O.getString("message").getValueOr("Unspecified error"));
std::string(O.getString("message").value_or("Unspecified error"));
if (auto Code = O.getInteger("code"))
return make_error<LSPError>(std::move(Msg), ErrorCode(*Code));
return error("{0}", Msg);

View File

@ -154,7 +154,7 @@ bool ABISysV_arc::IsRegisterFileReduced(RegisterContext &reg_ctx) const {
m_is_reg_file_reduced = (reg_value | rf_entries_bit) != 0;
}
return m_is_reg_file_reduced.getValueOr(false);
return m_is_reg_file_reduced.value_or(false);
}
//------------------------------------------------------------------
@ -458,7 +458,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread,
const uint32_t type_flags = compiler_type.GetTypeInfo();
// Integer return type.
if (type_flags & eTypeIsInteger) {
const size_t byte_size = compiler_type.GetByteSize(&thread).getValueOr(0);
const size_t byte_size = compiler_type.GetByteSize(&thread).value_or(0);
auto raw_value = ReadRawValue(reg_ctx, byte_size);
const bool is_signed = (type_flags & eTypeIsSigned) != 0;
@ -482,7 +482,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread,
if (compiler_type.IsFloatingPointType(float_count, is_complex) &&
1 == float_count && !is_complex) {
const size_t byte_size = compiler_type.GetByteSize(&thread).getValueOr(0);
const size_t byte_size = compiler_type.GetByteSize(&thread).value_or(0);
auto raw_value = ReadRawValue(reg_ctx, byte_size);
if (!SetSizedFloat(value.GetScalar(), raw_value, byte_size))

View File

@ -92,7 +92,7 @@ Expected<TraceIntelPTBundleLoader::ParsedProcess>
TraceIntelPTBundleLoader::ParseProcess(const JSONProcess &process) {
TargetSP target_sp;
Status error = m_debugger.GetTargetList().CreateTarget(
m_debugger, /*user_exe_path*/ StringRef(), process.triple.getValueOr(""),
m_debugger, /*user_exe_path*/ StringRef(), process.triple.value_or(""),
eLoadDependentsNo,
/*platform_options*/ nullptr, target_sp);

View File

@ -3144,11 +3144,10 @@ Error BitcodeReader::parseConstants() {
return error("Explicit gep operator type does not match pointee type "
"of pointer operand");
V = BitcodeConstant::create(
Alloc, CurTy,
{Instruction::GetElementPtr, InBounds, InRangeIndex.getValueOr(-1),
PointeeType},
Elts);
V = BitcodeConstant::create(Alloc, CurTy,
{Instruction::GetElementPtr, InBounds,
InRangeIndex.value_or(-1), PointeeType},
Elts);
break;
}
case bitc::CST_CODE_CE_SELECT: { // CE_SELECT: [opval#, opval#, opval#]

View File

@ -25,7 +25,7 @@ using namespace llvm;
using namespace llvm::symbolize;
MarkupFilter::MarkupFilter(raw_ostream &OS, Optional<bool> ColorsEnabled)
: OS(OS), ColorsEnabled(ColorsEnabled.getValueOr(
: OS(OS), ColorsEnabled(ColorsEnabled.value_or(
WithColor::defaultAutoDetectFunction()(OS))) {}
void MarkupFilter::beginLine(StringRef Line) {

View File

@ -27,8 +27,8 @@ namespace llvm {
HANDLE
llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *), void *Arg,
llvm::Optional<unsigned> StackSizeInBytes) {
HANDLE hThread = (HANDLE)::_beginthreadex(
NULL, StackSizeInBytes.getValueOr(0), ThreadFunc, Arg, 0, NULL);
HANDLE hThread = (HANDLE)::_beginthreadex(NULL, StackSizeInBytes.value_or(0),
ThreadFunc, Arg, 0, NULL);
if (!hThread) {
ReportLastErrorFatal("_beginthreadex failed");

View File

@ -106,7 +106,7 @@ TEST(Unicode, isPrintable) {
TEST(Unicode, nameToCodepointStrict) {
auto map = [](StringRef Str) {
return nameToCodepointStrict(Str).getValueOr(0xFFFF'FFFF);
return nameToCodepointStrict(Str).value_or(0xFFFF'FFFF);
};
// generated codepoints

View File

@ -244,8 +244,7 @@ StringRef AttrOrTypeParameter::getCppStorageType() const {
}
StringRef AttrOrTypeParameter::getConvertFromStorage() const {
return getDefValue<llvm::StringInit>("convertFromStorage")
.getValueOr("$_self");
return getDefValue<llvm::StringInit>("convertFromStorage").value_or("$_self");
}
Optional<StringRef> AttrOrTypeParameter::getParser() const {