std::optional::value => operator*/operator->

value() has undesired exception checking semantics and calls
__throw_bad_optional_access in libc++. Moreover, the API is unavailable without
_LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS).

This fixes check-llvm.
This commit is contained in:
Fangrui Song 2022-12-17 01:42:39 +00:00
parent 6d1d055fad
commit 67ba5c507a
27 changed files with 164 additions and 172 deletions

View File

@ -45,9 +45,9 @@ using remove_cvref_t // NOLINT(readability-identifier-naming)
// C++23.
template <typename T, typename Function>
auto transformOptional(const std::optional<T> &O, const Function &F)
-> std::optional<decltype(F(O.value()))> {
-> std::optional<decltype(F(*O))> {
if (O)
return F(O.value());
return F(*O);
return std::nullopt;
}
@ -55,9 +55,9 @@ auto transformOptional(const std::optional<T> &O, const Function &F)
// C++23.
template <typename T, typename Function>
auto transformOptional(std::optional<T> &&O, const Function &F)
-> std::optional<decltype(F(std::move(O).value()))> {
-> std::optional<decltype(F(*std::move(O)))> {
if (O)
return F(std::move(O).value());
return F(*std::move(O));
return std::nullopt;
}

View File

@ -399,7 +399,7 @@ void LVELFReader::processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
// marks functions that have been removed, by setting the value for the
// low_pc to the max address.
if (std::optional<uint64_t> Value = FormValue.getAsAddress()) {
CurrentLowPC = Value.value();
CurrentLowPC = *Value;
} else {
uint64_t UValue = FormValue.getRawUValue();
if (U->getAddrOffsetSectionItem(UValue)) {
@ -913,7 +913,7 @@ Error LVELFReader::createScopes() {
CU->getVersion() >= 5
? dwarf::toString(UnitDie.find(dwarf::DW_AT_dwo_name))
: dwarf::toString(UnitDie.find(dwarf::DW_AT_GNU_dwo_name));
StringRef From(DWOFileName.has_value() ? DWOFileName.value() : "");
StringRef From(DWOFileName.value_or(""));
DWOAlternativeLocation = createAlternativePath(From);
}

View File

@ -407,13 +407,13 @@ Error DebuginfodCollection::findBinaries(StringRef Path) {
if (!ID)
continue;
std::string IDString = buildIDToString(ID.value());
std::string IDString = buildIDToString(*ID);
if (Object->hasDebugInfo()) {
std::lock_guard<sys::RWMutex> DebugBinariesGuard(DebugBinariesMutex);
DebugBinaries[IDString] = FilePath;
(void)DebugBinaries.try_emplace(IDString, std::move(FilePath));
} else {
std::lock_guard<sys::RWMutex> BinariesGuard(BinariesMutex);
Binaries[IDString] = FilePath;
(void)Binaries.try_emplace(IDString, std::move(FilePath));
}
}
});

View File

@ -599,8 +599,8 @@ handleUserSection(const NewSectionInfo &NewSection,
static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
Object &Obj) {
if (Config.OutputArch) {
Obj.Machine = Config.OutputArch.value().EMachine;
Obj.OSABI = Config.OutputArch.value().OSABI;
Obj.Machine = Config.OutputArch->EMachine;
Obj.OSABI = Config.OutputArch->OSABI;
}
if (!Config.SplitDWO.empty() && Config.ExtractDWO) {
@ -698,7 +698,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
const SectionRename &SR = Iter->second;
Sec.Name = std::string(SR.NewName);
if (SR.NewFlags)
setSectionFlagsAndType(Sec, SR.NewFlags.value());
setSectionFlagsAndType(Sec, *SR.NewFlags);
RenamedSections.insert(&Sec);
} else if (RelocSec && !(Sec.Flags & SHF_ALLOC))
// Postpone processing relocation sections which are not specified in
@ -809,9 +809,9 @@ Error objcopy::elf::executeObjcopyOnBinary(const CommonConfig &Config,
if (!Obj)
return Obj.takeError();
// Prefer OutputArch (-O<format>) if set, otherwise infer it from the input.
const ElfType OutputElfType =
Config.OutputArch ? getOutputElfType(Config.OutputArch.value())
: getOutputElfType(In);
const ElfType OutputElfType = Config.OutputArch
? getOutputElfType(*Config.OutputArch)
: getOutputElfType(In);
if (Error E = handleArgs(Config, ELFConfig, **Obj))
return createFileError(Config.InputFilename, std::move(E));

View File

@ -141,17 +141,17 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
// Compute the optional fields if needed...
if (P.Program->DXILOffset)
Header.Bitcode.Offset = P.Program->DXILOffset.value();
Header.Bitcode.Offset = *P.Program->DXILOffset;
else
Header.Bitcode.Offset = sizeof(dxbc::BitcodeHeader);
if (P.Program->DXILSize)
Header.Bitcode.Size = P.Program->DXILSize.value();
Header.Bitcode.Size = *P.Program->DXILSize;
else
Header.Bitcode.Size = P.Program->DXIL ? P.Program->DXIL->size() : 0;
if (P.Program->Size)
Header.Size = P.Program->Size.value();
Header.Size = *P.Program->Size;
else
Header.Size = sizeof(dxbc::ProgramHeader) + Header.Bitcode.Size;

View File

@ -577,7 +577,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
std::optional<CodeModel::Model> CM_IR = M->getCodeModel();
if (!CM && CM_IR)
Target->setCodeModel(CM_IR.value());
Target->setCodeModel(*CM_IR);
} else {
TheTriple = Triple(Triple::normalize(TargetTriple));
if (TheTriple.getTriple().empty())

View File

@ -490,9 +490,9 @@ int main(int argc, char **argv, char * const *envp) {
builder.setMCPU(codegen::getCPUStr());
builder.setMAttrs(codegen::getFeatureList());
if (auto RM = codegen::getExplicitRelocModel())
builder.setRelocationModel(RM.value());
builder.setRelocationModel(*RM);
if (auto CM = codegen::getExplicitCodeModel())
builder.setCodeModel(CM.value());
builder.setCodeModel(*CM);
builder.setErrorStr(&ErrorMsg);
builder.setEngineKind(ForceInterpreter
? EngineKind::Interpreter

View File

@ -290,8 +290,8 @@ void CoverageExporterJson::renderRoot(ArrayRef<std::string> SourceFiles) {
const json::Object *ObjB = B.getAsObject();
assert(ObjA != nullptr && "Value A was not an Object");
assert(ObjB != nullptr && "Value B was not an Object");
const StringRef FilenameA = ObjA->getString("filename").value();
const StringRef FilenameB = ObjB->getString("filename").value();
const StringRef FilenameA = *ObjA->getString("filename");
const StringRef FilenameB = *ObjB->getString("filename");
return FilenameA.compare(FilenameB) < 0;
});
auto Export = json::Object(

View File

@ -534,33 +534,32 @@ int llvm_ifs_main(int argc, char **argv) {
<< "Triple should be defined when output format is TBD";
return -1;
}
return writeTbdStub(llvm::Triple(Stub.Target.Triple.value()),
Stub.Symbols, "TBD", Out);
return writeTbdStub(llvm::Triple(*Stub.Target.Triple), Stub.Symbols,
"TBD", Out);
}
case FileFormat::IFS: {
Stub.IfsVersion = IfsVersionCurrent;
if (Config.InputFormat.value() == FileFormat::ELF &&
Config.HintIfsTarget) {
if (*Config.InputFormat == FileFormat::ELF && Config.HintIfsTarget) {
std::error_code HintEC(1, std::generic_category());
IFSTarget HintTarget = parseTriple(*Config.HintIfsTarget);
if (Stub.Target.Arch.value() != HintTarget.Arch.value())
if (*Stub.Target.Arch != *HintTarget.Arch)
fatalError(make_error<StringError>(
"Triple hint does not match the actual architecture", HintEC));
if (Stub.Target.Endianness.value() != HintTarget.Endianness.value())
if (*Stub.Target.Endianness != *HintTarget.Endianness)
fatalError(make_error<StringError>(
"Triple hint does not match the actual endianness", HintEC));
if (Stub.Target.BitWidth.value() != HintTarget.BitWidth.value())
if (*Stub.Target.BitWidth != *HintTarget.BitWidth)
fatalError(make_error<StringError>(
"Triple hint does not match the actual bit width", HintEC));
stripIFSTarget(Stub, true, false, false, false);
Stub.Target.Triple = Config.HintIfsTarget.value();
Stub.Target.Triple = *Config.HintIfsTarget;
} else {
stripIFSTarget(Stub, Config.StripIfsTarget, Config.StripIfsArch,
Config.StripIfsEndianness, Config.StripIfsBitwidth);
}
Error IFSWriteError =
writeIFS(Config.Output.value(), Stub, Config.WriteIfChanged);
writeIFS(*Config.Output, Stub, Config.WriteIfChanged);
if (IFSWriteError)
fatalError(std::move(IFSWriteError));
break;
@ -589,28 +588,27 @@ int llvm_ifs_main(int argc, char **argv) {
}
if (Config.OutputIfs) {
Stub.IfsVersion = IfsVersionCurrent;
if (Config.InputFormat.value() == FileFormat::ELF &&
Config.HintIfsTarget) {
if (*Config.InputFormat == FileFormat::ELF && Config.HintIfsTarget) {
std::error_code HintEC(1, std::generic_category());
IFSTarget HintTarget = parseTriple(*Config.HintIfsTarget);
if (Stub.Target.Arch.value() != HintTarget.Arch.value())
if (*Stub.Target.Arch != *HintTarget.Arch)
fatalError(make_error<StringError>(
"Triple hint does not match the actual architecture", HintEC));
if (Stub.Target.Endianness.value() != HintTarget.Endianness.value())
if (*Stub.Target.Endianness != *HintTarget.Endianness)
fatalError(make_error<StringError>(
"Triple hint does not match the actual endianness", HintEC));
if (Stub.Target.BitWidth.value() != HintTarget.BitWidth.value())
if (*Stub.Target.BitWidth != *HintTarget.BitWidth)
fatalError(make_error<StringError>(
"Triple hint does not match the actual bit width", HintEC));
stripIFSTarget(Stub, true, false, false, false);
Stub.Target.Triple = Config.HintIfsTarget.value();
Stub.Target.Triple = *Config.HintIfsTarget;
} else {
stripIFSTarget(Stub, Config.StripIfsTarget, Config.StripIfsArch,
Config.StripIfsEndianness, Config.StripIfsBitwidth);
}
Error IFSWriteError =
writeIFS(Config.OutputIfs.value(), Stub, Config.WriteIfChanged);
writeIFS(*Config.OutputIfs, Stub, Config.WriteIfChanged);
if (IFSWriteError)
fatalError(std::move(IFSWriteError));
}
@ -627,8 +625,8 @@ int llvm_ifs_main(int argc, char **argv) {
<< "Triple should be defined when output format is TBD";
return -1;
}
return writeTbdStub(llvm::Triple(Stub.Target.Triple.value()),
Stub.Symbols, "TBD", Out);
return writeTbdStub(llvm::Triple(*Stub.Target.Triple), Stub.Symbols,
"TBD", Out);
}
}
return 0;

View File

@ -71,7 +71,7 @@ void InstructionInfoView::printView(raw_ostream &OS) const {
TempStream << ' ';
if (IIVDEntry.RThroughput) {
double RT = IIVDEntry.RThroughput.value();
double RT = *IIVDEntry.RThroughput;
TempStream << format("%.2f", RT) << ' ';
if (RT < 10.0)
TempStream << " ";

View File

@ -94,9 +94,9 @@ std::string objdump::getXCOFFSymbolDescription(const SymbolInfoTy &SymbolInfo,
std::string Result;
// Dummy symbols have no symbol index.
if (SymbolInfo.XCOFFSymInfo.Index)
Result = ("(idx: " + Twine(SymbolInfo.XCOFFSymInfo.Index.value()) + ") " +
SymbolName)
.str();
Result =
("(idx: " + Twine(*SymbolInfo.XCOFFSymInfo.Index) + ") " + SymbolName)
.str();
else
Result.append(SymbolName.begin(), SymbolName.end());

View File

@ -1691,7 +1691,7 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj,
continue;
}
if (Status.value() == MCDisassembler::Fail) {
if (*Status == MCDisassembler::Fail) {
// If onSymbolStart returns Fail, that means it identified some kind
// of special data at this address, but wasn't able to disassemble it
// meaningfully. So we fall back to disassembling the failed region
@ -2505,8 +2505,8 @@ void objdump::printSymbol(const ObjectFile &O, const SymbolRef &Symbol,
SymName = demangle(SymName);
if (SymbolDescription)
SymName = getXCOFFSymbolDescription(
createSymbolInfo(O, SymRef.value()), SymName);
SymName = getXCOFFSymbolDescription(createSymbolInfo(O, *SymRef),
SymName);
outs() << ' ' << SymName;
outs() << ") ";
@ -2614,7 +2614,7 @@ static void printRawClangAST(const ObjectFile *Obj) {
return;
StringRef ClangASTContents =
unwrapOrError(ClangASTSection.value().getContents(), Obj->getFileName());
unwrapOrError(ClangASTSection->getContents(), Obj->getFileName());
outs().write(ClangASTContents.data(), ClangASTContents.size());
}

View File

@ -90,8 +90,8 @@ exportToFile(const StringRef FilePath,
assert(End && "Could not find instruction number for last instruction");
J.object([&] {
J.attribute("start", Start.value());
J.attribute("end", End.value());
J.attribute("start", *Start);
J.attribute("end", *End);
});
}
J.arrayEnd();

View File

@ -248,15 +248,15 @@ void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
auto FormValue = DIEWrapper.find(AttrSpec.Attr);
if (!FormValue)
return;
auto Form = FormValue.value().getForm();
auto Form = FormValue->getForm();
bool indirect = false;
do {
indirect = false;
switch (Form) {
case dwarf::DW_FORM_addr:
case dwarf::DW_FORM_GNU_addr_index:
if (auto Val = FormValue.value().getAsAddress())
NewValue.Value = Val.value();
if (auto Val = FormValue->getAsAddress())
NewValue.Value = *Val;
break;
case dwarf::DW_FORM_ref_addr:
case dwarf::DW_FORM_ref1:
@ -265,16 +265,16 @@ void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
case dwarf::DW_FORM_ref8:
case dwarf::DW_FORM_ref_udata:
case dwarf::DW_FORM_ref_sig8:
if (auto Val = FormValue.value().getAsReferenceUVal())
NewValue.Value = Val.value();
if (auto Val = FormValue->getAsReferenceUVal())
NewValue.Value = *Val;
break;
case dwarf::DW_FORM_exprloc:
case dwarf::DW_FORM_block:
case dwarf::DW_FORM_block1:
case dwarf::DW_FORM_block2:
case dwarf::DW_FORM_block4:
if (auto Val = FormValue.value().getAsBlock()) {
auto BlockData = Val.value();
if (auto Val = FormValue->getAsBlock()) {
auto BlockData = *Val;
std::copy(BlockData.begin(), BlockData.end(),
std::back_inserter(NewValue.BlockData));
}
@ -289,8 +289,8 @@ void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
case dwarf::DW_FORM_udata:
case dwarf::DW_FORM_ref_sup4:
case dwarf::DW_FORM_ref_sup8:
if (auto Val = FormValue.value().getAsUnsignedConstant())
NewValue.Value = Val.value();
if (auto Val = FormValue->getAsUnsignedConstant())
NewValue.Value = *Val;
break;
case dwarf::DW_FORM_string:
if (auto Val = dwarf::toString(FormValue))
@ -298,10 +298,10 @@ void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
break;
case dwarf::DW_FORM_indirect:
indirect = true;
if (auto Val = FormValue.value().getAsUnsignedConstant()) {
NewValue.Value = Val.value();
if (auto Val = FormValue->getAsUnsignedConstant()) {
NewValue.Value = *Val;
NewEntry.Values.push_back(NewValue);
Form = static_cast<dwarf::Form>(Val.value());
Form = static_cast<dwarf::Form>(*Val);
}
break;
case dwarf::DW_FORM_strp:
@ -312,8 +312,8 @@ void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
case dwarf::DW_FORM_strp_sup:
case dwarf::DW_FORM_GNU_str_index:
case dwarf::DW_FORM_strx:
if (auto Val = FormValue.value().getAsCStringOffset())
NewValue.Value = Val.value();
if (auto Val = FormValue->getAsCStringOffset())
NewValue.Value = *Val;
break;
case dwarf::DW_FORM_flag_present:
NewValue.Value = 1;

View File

@ -54,7 +54,7 @@ TEST(TransformTest, TransformStd) {
A = 3;
std::optional<int> C = llvm::transformOptional(A, [&](int N) { return N + 1; });
EXPECT_TRUE(C.has_value());
EXPECT_EQ(4, C.value());
EXPECT_EQ(4, *C);
}
TEST(TransformTest, MoveTransformStd) {
@ -75,7 +75,7 @@ TEST(TransformTest, MoveTransformStd) {
std::optional<int> C = llvm::transformOptional(
std::move(A), [&](const MoveOnly &M) { return M.val + 2; });
EXPECT_TRUE(C.has_value());
EXPECT_EQ(7, C.value());
EXPECT_EQ(7, *C);
EXPECT_EQ(0u, MoveOnly::MoveConstructions);
EXPECT_EQ(0u, MoveOnly::MoveAssignments);
EXPECT_EQ(0u, MoveOnly::Destructions);
@ -90,7 +90,7 @@ TEST(TransformTest, TransformLlvm) {
A = 3;
llvm::Optional<int> C = llvm::transformOptional(A, [&](int N) { return N + 1; });
EXPECT_TRUE(C.has_value());
EXPECT_EQ(4, C.value());
EXPECT_EQ(4, *C);
}
TEST(TransformTest, MoveTransformLlvm) {
@ -111,7 +111,7 @@ TEST(TransformTest, MoveTransformLlvm) {
llvm::Optional<int> C = llvm::transformOptional(
std::move(A), [&](const MoveOnly &M) { return M.val + 2; });
EXPECT_TRUE(C.has_value());
EXPECT_EQ(7, C.value());
EXPECT_EQ(7, *C);
EXPECT_EQ(0u, MoveOnly::MoveConstructions);
EXPECT_EQ(0u, MoveOnly::MoveAssignments);
EXPECT_EQ(0u, MoveOnly::Destructions);

View File

@ -75,11 +75,11 @@ TEST_F(BlockFrequencyInfoTest, Basic) {
EXPECT_EQ(BB0Freq, BB1Freq + BB2Freq);
EXPECT_EQ(BB0Freq, BB3Freq);
EXPECT_EQ(BFI.getBlockProfileCount(&BB0).value(), UINT64_C(100));
EXPECT_EQ(BFI.getBlockProfileCount(BB3).value(), UINT64_C(100));
EXPECT_EQ(BFI.getBlockProfileCount(BB1).value(),
EXPECT_EQ(*BFI.getBlockProfileCount(&BB0), UINT64_C(100));
EXPECT_EQ(*BFI.getBlockProfileCount(BB3), UINT64_C(100));
EXPECT_EQ(*BFI.getBlockProfileCount(BB1),
(100 * BB1Freq + BB0Freq / 2) / BB0Freq);
EXPECT_EQ(BFI.getBlockProfileCount(BB2).value(),
EXPECT_EQ(*BFI.getBlockProfileCount(BB2),
(100 * BB2Freq + BB0Freq / 2) / BB0Freq);
// Scale the frequencies of BB0, BB1 and BB2 by a factor of two.

View File

@ -76,7 +76,7 @@ protected:
const auto OptInfo = VFABI::tryDemangleForVFABI(MangledName, *(M.get()));
if (OptInfo) {
Info = OptInfo.value();
Info = *OptInfo;
return true;
}

View File

@ -83,131 +83,131 @@ TEST_F(AArch64GISelMITest, FoldBinOp) {
std::optional<APInt> FoldGAddInt = ConstantFoldBinOp(
TargetOpcode::G_ADD, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGAddInt.has_value());
EXPECT_EQ(25ULL, FoldGAddInt.value().getLimitedValue());
EXPECT_EQ(25ULL, FoldGAddInt->getLimitedValue());
std::optional<APInt> FoldGAddMix = ConstantFoldBinOp(
TargetOpcode::G_ADD, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGAddMix.has_value());
EXPECT_EQ(1073741840ULL, FoldGAddMix.value().getLimitedValue());
EXPECT_EQ(1073741840ULL, FoldGAddMix->getLimitedValue());
// Test G_AND folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGAndInt = ConstantFoldBinOp(
TargetOpcode::G_AND, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGAndInt.has_value());
EXPECT_EQ(0ULL, FoldGAndInt.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGAndInt->getLimitedValue());
std::optional<APInt> FoldGAndMix = ConstantFoldBinOp(
TargetOpcode::G_AND, MIBCst2.getReg(0), MIBFCst1.getReg(0), *MRI);
EXPECT_TRUE(FoldGAndMix.has_value());
EXPECT_EQ(1ULL, FoldGAndMix.value().getLimitedValue());
EXPECT_EQ(1ULL, FoldGAndMix->getLimitedValue());
// Test G_ASHR folding Integer + Mixed cases
std::optional<APInt> FoldGAShrInt = ConstantFoldBinOp(
TargetOpcode::G_ASHR, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGAShrInt.has_value());
EXPECT_EQ(0ULL, FoldGAShrInt.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGAShrInt->getLimitedValue());
std::optional<APInt> FoldGAShrMix = ConstantFoldBinOp(
TargetOpcode::G_ASHR, MIBFCst2.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGAShrMix.has_value());
EXPECT_EQ(2097152ULL, FoldGAShrMix.value().getLimitedValue());
EXPECT_EQ(2097152ULL, FoldGAShrMix->getLimitedValue());
// Test G_LSHR folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGLShrInt = ConstantFoldBinOp(
TargetOpcode::G_LSHR, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGLShrInt.has_value());
EXPECT_EQ(0ULL, FoldGLShrInt.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGLShrInt->getLimitedValue());
std::optional<APInt> FoldGLShrMix = ConstantFoldBinOp(
TargetOpcode::G_LSHR, MIBFCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGLShrMix.has_value());
EXPECT_EQ(2080768ULL, FoldGLShrMix.value().getLimitedValue());
EXPECT_EQ(2080768ULL, FoldGLShrMix->getLimitedValue());
// Test G_MUL folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGMulInt = ConstantFoldBinOp(
TargetOpcode::G_MUL, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGMulInt.has_value());
EXPECT_EQ(144ULL, FoldGMulInt.value().getLimitedValue());
EXPECT_EQ(144ULL, FoldGMulInt->getLimitedValue());
std::optional<APInt> FoldGMulMix = ConstantFoldBinOp(
TargetOpcode::G_MUL, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGMulMix.has_value());
EXPECT_EQ(0ULL, FoldGMulMix.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGMulMix->getLimitedValue());
// Test G_OR folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGOrInt = ConstantFoldBinOp(
TargetOpcode::G_OR, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGOrInt.has_value());
EXPECT_EQ(25ULL, FoldGOrInt.value().getLimitedValue());
EXPECT_EQ(25ULL, FoldGOrInt->getLimitedValue());
std::optional<APInt> FoldGOrMix = ConstantFoldBinOp(
TargetOpcode::G_OR, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGOrMix.has_value());
EXPECT_EQ(1073741840ULL, FoldGOrMix.value().getLimitedValue());
EXPECT_EQ(1073741840ULL, FoldGOrMix->getLimitedValue());
// Test G_SHL folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGShlInt = ConstantFoldBinOp(
TargetOpcode::G_SHL, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGShlInt.has_value());
EXPECT_EQ(8192ULL, FoldGShlInt.value().getLimitedValue());
EXPECT_EQ(8192ULL, FoldGShlInt->getLimitedValue());
std::optional<APInt> FoldGShlMix = ConstantFoldBinOp(
TargetOpcode::G_SHL, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGShlMix.has_value());
EXPECT_EQ(0ULL, FoldGShlMix.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGShlMix->getLimitedValue());
// Test G_SUB folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGSubInt = ConstantFoldBinOp(
TargetOpcode::G_SUB, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGSubInt.has_value());
EXPECT_EQ(7ULL, FoldGSubInt.value().getLimitedValue());
EXPECT_EQ(7ULL, FoldGSubInt->getLimitedValue());
std::optional<APInt> FoldGSubMix = ConstantFoldBinOp(
TargetOpcode::G_SUB, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGSubMix.has_value());
EXPECT_EQ(3221225488ULL, FoldGSubMix.value().getLimitedValue());
EXPECT_EQ(3221225488ULL, FoldGSubMix->getLimitedValue());
// Test G_XOR folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGXorInt = ConstantFoldBinOp(
TargetOpcode::G_XOR, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGXorInt.has_value());
EXPECT_EQ(25ULL, FoldGXorInt.value().getLimitedValue());
EXPECT_EQ(25ULL, FoldGXorInt->getLimitedValue());
std::optional<APInt> FoldGXorMix = ConstantFoldBinOp(
TargetOpcode::G_XOR, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGXorMix.has_value());
EXPECT_EQ(1073741840ULL, FoldGXorMix.value().getLimitedValue());
EXPECT_EQ(1073741840ULL, FoldGXorMix->getLimitedValue());
// Test G_UDIV folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGUdivInt = ConstantFoldBinOp(
TargetOpcode::G_UDIV, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGUdivInt.has_value());
EXPECT_EQ(1ULL, FoldGUdivInt.value().getLimitedValue());
EXPECT_EQ(1ULL, FoldGUdivInt->getLimitedValue());
std::optional<APInt> FoldGUdivMix = ConstantFoldBinOp(
TargetOpcode::G_UDIV, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGUdivMix.has_value());
EXPECT_EQ(0ULL, FoldGUdivMix.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGUdivMix->getLimitedValue());
// Test G_SDIV folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGSdivInt = ConstantFoldBinOp(
TargetOpcode::G_SDIV, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGSdivInt.has_value());
EXPECT_EQ(1ULL, FoldGSdivInt.value().getLimitedValue());
EXPECT_EQ(1ULL, FoldGSdivInt->getLimitedValue());
std::optional<APInt> FoldGSdivMix = ConstantFoldBinOp(
TargetOpcode::G_SDIV, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGSdivMix.has_value());
EXPECT_EQ(0ULL, FoldGSdivMix.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGSdivMix->getLimitedValue());
// Test G_UREM folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGUremInt = ConstantFoldBinOp(
TargetOpcode::G_UDIV, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGUremInt.has_value());
EXPECT_EQ(1ULL, FoldGUremInt.value().getLimitedValue());
EXPECT_EQ(1ULL, FoldGUremInt->getLimitedValue());
std::optional<APInt> FoldGUremMix = ConstantFoldBinOp(
TargetOpcode::G_UDIV, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGUremMix.has_value());
EXPECT_EQ(0ULL, FoldGUremMix.value().getLimitedValue());
EXPECT_EQ(0ULL, FoldGUremMix->getLimitedValue());
// Test G_SREM folding Integer + Mixed Int-Float cases
std::optional<APInt> FoldGSremInt = ConstantFoldBinOp(
TargetOpcode::G_SREM, MIBCst1.getReg(0), MIBCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGSremInt.has_value());
EXPECT_EQ(7ULL, FoldGSremInt.value().getLimitedValue());
EXPECT_EQ(7ULL, FoldGSremInt->getLimitedValue());
std::optional<APInt> FoldGSremMix = ConstantFoldBinOp(
TargetOpcode::G_SREM, MIBCst1.getReg(0), MIBFCst2.getReg(0), *MRI);
EXPECT_TRUE(FoldGSremMix.has_value());
EXPECT_EQ(16ULL, FoldGSremMix.value().getLimitedValue());
EXPECT_EQ(16ULL, FoldGSremMix->getLimitedValue());
}
} // namespace

View File

@ -252,7 +252,7 @@ void TestAllForms() {
EXPECT_TRUE((bool)FormValue);
BlockDataOpt = FormValue->getAsBlock();
EXPECT_TRUE(BlockDataOpt.has_value());
ExtractedBlockData = BlockDataOpt.value();
ExtractedBlockData = *BlockDataOpt;
EXPECT_EQ(ExtractedBlockData.size(), BlockSize);
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0);
@ -260,7 +260,7 @@ void TestAllForms() {
EXPECT_TRUE((bool)FormValue);
BlockDataOpt = FormValue->getAsBlock();
EXPECT_TRUE(BlockDataOpt.has_value());
ExtractedBlockData = BlockDataOpt.value();
ExtractedBlockData = *BlockDataOpt;
EXPECT_EQ(ExtractedBlockData.size(), BlockSize);
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0);
@ -268,7 +268,7 @@ void TestAllForms() {
EXPECT_TRUE((bool)FormValue);
BlockDataOpt = FormValue->getAsBlock();
EXPECT_TRUE(BlockDataOpt.has_value());
ExtractedBlockData = BlockDataOpt.value();
ExtractedBlockData = *BlockDataOpt;
EXPECT_EQ(ExtractedBlockData.size(), BlockSize);
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0);
@ -276,7 +276,7 @@ void TestAllForms() {
EXPECT_TRUE((bool)FormValue);
BlockDataOpt = FormValue->getAsBlock();
EXPECT_TRUE(BlockDataOpt.has_value());
ExtractedBlockData = BlockDataOpt.value();
ExtractedBlockData = *BlockDataOpt;
EXPECT_EQ(ExtractedBlockData.size(), BlockSize);
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0);
@ -286,7 +286,7 @@ void TestAllForms() {
EXPECT_TRUE((bool)FormValue);
BlockDataOpt = FormValue->getAsBlock();
EXPECT_TRUE(BlockDataOpt.has_value());
ExtractedBlockData = BlockDataOpt.value();
ExtractedBlockData = *BlockDataOpt;
EXPECT_EQ(ExtractedBlockData.size(), 16u);
EXPECT_TRUE(memcmp(ExtractedBlockData.data(), Data16, 16) == 0);
}
@ -988,21 +988,21 @@ template <uint16_t Version, class AddrType> void TestAddresses() {
EXPECT_FALSE((bool)OptU64);
} else {
EXPECT_TRUE((bool)OptU64);
EXPECT_EQ(OptU64.value(), ActualHighPC);
EXPECT_EQ(*OptU64, ActualHighPC);
}
// Get the high PC as an unsigned constant. This should succeed if the high PC
// was encoded as an offset and fail if the high PC was encoded as an address.
OptU64 = toUnsigned(SubprogramDieLowHighPC.find(DW_AT_high_pc));
if (SupportsHighPCAsOffset) {
EXPECT_TRUE((bool)OptU64);
EXPECT_EQ(OptU64.value(), ActualHighPCOffset);
EXPECT_EQ(*OptU64, ActualHighPCOffset);
} else {
EXPECT_FALSE((bool)OptU64);
}
OptU64 = SubprogramDieLowHighPC.getHighPC(ActualLowPC);
EXPECT_TRUE((bool)OptU64);
EXPECT_EQ(OptU64.value(), ActualHighPC);
EXPECT_EQ(*OptU64, ActualHighPC);
EXPECT_TRUE(SubprogramDieLowHighPC.getLowAndHighPC(LowPC, HighPC, SectionIndex));
EXPECT_EQ(LowPC, ActualLowPC);

View File

@ -79,16 +79,16 @@ TEST(DWARFFormValue, SignedConstantForms) {
auto Sign2 = createDataXFormValue<uint16_t>(DW_FORM_data2, -12345);
auto Sign4 = createDataXFormValue<uint32_t>(DW_FORM_data4, -123456789);
auto Sign8 = createDataXFormValue<uint64_t>(DW_FORM_data8, -1);
EXPECT_EQ(Sign1.getAsSignedConstant().value(), -123);
EXPECT_EQ(Sign2.getAsSignedConstant().value(), -12345);
EXPECT_EQ(Sign4.getAsSignedConstant().value(), -123456789);
EXPECT_EQ(Sign8.getAsSignedConstant().value(), -1);
EXPECT_EQ(*Sign1.getAsSignedConstant(), -123);
EXPECT_EQ(*Sign2.getAsSignedConstant(), -12345);
EXPECT_EQ(*Sign4.getAsSignedConstant(), -123456789);
EXPECT_EQ(*Sign8.getAsSignedConstant(), -1);
// Check that we can handle big positive values, but that we return
// an error just over the limit.
auto UMax = createULEBFormValue(LLONG_MAX);
auto TooBig = createULEBFormValue(uint64_t(LLONG_MAX) + 1);
EXPECT_EQ(UMax.getAsSignedConstant().value(), LLONG_MAX);
EXPECT_EQ(*UMax.getAsSignedConstant(), LLONG_MAX);
EXPECT_EQ(TooBig.getAsSignedConstant().has_value(), false);
// Sanity check some other forms.
@ -100,14 +100,14 @@ TEST(DWARFFormValue, SignedConstantForms) {
auto LEBMax = createSLEBFormValue(LLONG_MAX);
auto LEB1 = createSLEBFormValue(-42);
auto LEB2 = createSLEBFormValue(42);
EXPECT_EQ(Data1.getAsSignedConstant().value(), 120);
EXPECT_EQ(Data2.getAsSignedConstant().value(), 32000);
EXPECT_EQ(Data4.getAsSignedConstant().value(), 2000000000);
EXPECT_EQ(Data8.getAsSignedConstant().value(), 0x1234567812345678LL);
EXPECT_EQ(LEBMin.getAsSignedConstant().value(), LLONG_MIN);
EXPECT_EQ(LEBMax.getAsSignedConstant().value(), LLONG_MAX);
EXPECT_EQ(LEB1.getAsSignedConstant().value(), -42);
EXPECT_EQ(LEB2.getAsSignedConstant().value(), 42);
EXPECT_EQ(*Data1.getAsSignedConstant(), 120);
EXPECT_EQ(*Data2.getAsSignedConstant(), 32000);
EXPECT_EQ(*Data4.getAsSignedConstant(), 2000000000);
EXPECT_EQ(*Data8.getAsSignedConstant(), 0x1234567812345678LL);
EXPECT_EQ(*LEBMin.getAsSignedConstant(), LLONG_MIN);
EXPECT_EQ(*LEBMax.getAsSignedConstant(), LLONG_MAX);
EXPECT_EQ(*LEB1.getAsSignedConstant(), -42);
EXPECT_EQ(*LEB2.getAsSignedConstant(), 42);
// Data16 is a little tricky.
char Cksum[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};

View File

@ -1116,51 +1116,46 @@ TEST_F(DILocationTest, cloneTemporary) {
}
TEST_F(DILocationTest, discriminatorEncoding) {
EXPECT_EQ(0U, DILocation::encodeDiscriminator(0, 0, 0).value());
EXPECT_EQ(0U, *DILocation::encodeDiscriminator(0, 0, 0));
// Encode base discriminator as a component: lsb is 0, then the value.
// The other components are all absent, so we leave all the other bits 0.
EXPECT_EQ(2U, DILocation::encodeDiscriminator(1, 0, 0).value());
EXPECT_EQ(2U, *DILocation::encodeDiscriminator(1, 0, 0));
// Base discriminator component is empty, so lsb is 1. Next component is not
// empty, so its lsb is 0, then its value (1). Next component is empty.
// So the bit pattern is 101.
EXPECT_EQ(5U, DILocation::encodeDiscriminator(0, 1, 0).value());
EXPECT_EQ(5U, *DILocation::encodeDiscriminator(0, 1, 0));
// First 2 components are empty, so the bit pattern is 11. Then the
// next component - ending up with 1011.
EXPECT_EQ(0xbU, DILocation::encodeDiscriminator(0, 0, 1).value());
EXPECT_EQ(0xbU, *DILocation::encodeDiscriminator(0, 0, 1));
// The bit pattern for the first 2 components is 11. The next bit is 0,
// because the last component is not empty. We have 29 bits usable for
// encoding, but we cap it at 12 bits uniformously for all components. We
// encode the last component over 14 bits.
EXPECT_EQ(0xfffbU, DILocation::encodeDiscriminator(0, 0, 0xfff).value());
EXPECT_EQ(0xfffbU, *DILocation::encodeDiscriminator(0, 0, 0xfff));
EXPECT_EQ(0x102U, DILocation::encodeDiscriminator(1, 1, 0).value());
EXPECT_EQ(0x102U, *DILocation::encodeDiscriminator(1, 1, 0));
EXPECT_EQ(0x13eU, DILocation::encodeDiscriminator(0x1f, 1, 0).value());
EXPECT_EQ(0x13eU, *DILocation::encodeDiscriminator(0x1f, 1, 0));
EXPECT_EQ(0x87feU, DILocation::encodeDiscriminator(0x1ff, 1, 0).value());
EXPECT_EQ(0x87feU, *DILocation::encodeDiscriminator(0x1ff, 1, 0));
EXPECT_EQ(0x1f3eU, DILocation::encodeDiscriminator(0x1f, 0x1f, 0).value());
EXPECT_EQ(0x1f3eU, *DILocation::encodeDiscriminator(0x1f, 0x1f, 0));
EXPECT_EQ(0x3ff3eU, DILocation::encodeDiscriminator(0x1f, 0x1ff, 0).value());
EXPECT_EQ(0x3ff3eU, *DILocation::encodeDiscriminator(0x1f, 0x1ff, 0));
EXPECT_EQ(0x1ff87feU,
DILocation::encodeDiscriminator(0x1ff, 0x1ff, 0).value());
EXPECT_EQ(0x1ff87feU, *DILocation::encodeDiscriminator(0x1ff, 0x1ff, 0));
EXPECT_EQ(0xfff9f3eU,
DILocation::encodeDiscriminator(0x1f, 0x1f, 0xfff).value());
EXPECT_EQ(0xfff9f3eU, *DILocation::encodeDiscriminator(0x1f, 0x1f, 0xfff));
EXPECT_EQ(0xffc3ff3eU,
DILocation::encodeDiscriminator(0x1f, 0x1ff, 0x1ff).value());
EXPECT_EQ(0xffc3ff3eU, *DILocation::encodeDiscriminator(0x1f, 0x1ff, 0x1ff));
EXPECT_EQ(0xffcf87feU,
DILocation::encodeDiscriminator(0x1ff, 0x1f, 0x1ff).value());
EXPECT_EQ(0xffcf87feU, *DILocation::encodeDiscriminator(0x1ff, 0x1f, 0x1ff));
EXPECT_EQ(0xe1ff87feU,
DILocation::encodeDiscriminator(0x1ff, 0x1ff, 7).value());
EXPECT_EQ(0xe1ff87feU, *DILocation::encodeDiscriminator(0x1ff, 0x1ff, 7));
}
TEST_F(DILocationTest, discriminatorEncodingNegativeTests) {
@ -1182,36 +1177,35 @@ TEST_F(DILocationTest, discriminatorSpecialCases) {
EXPECT_EQ(0U, L1->getBaseDiscriminator());
EXPECT_EQ(1U, L1->getDuplicationFactor());
EXPECT_EQ(L1, L1->cloneWithBaseDiscriminator(0).value());
EXPECT_EQ(L1, L1->cloneByMultiplyingDuplicationFactor(0).value());
EXPECT_EQ(L1, L1->cloneByMultiplyingDuplicationFactor(1).value());
EXPECT_EQ(L1, *L1->cloneWithBaseDiscriminator(0));
EXPECT_EQ(L1, *L1->cloneByMultiplyingDuplicationFactor(0));
EXPECT_EQ(L1, *L1->cloneByMultiplyingDuplicationFactor(1));
auto L2 = L1->cloneWithBaseDiscriminator(1).value();
auto L2 = *L1->cloneWithBaseDiscriminator(1);
EXPECT_EQ(0U, L1->getBaseDiscriminator());
EXPECT_EQ(1U, L1->getDuplicationFactor());
EXPECT_EQ(1U, L2->getBaseDiscriminator());
EXPECT_EQ(1U, L2->getDuplicationFactor());
auto L3 = L2->cloneByMultiplyingDuplicationFactor(2).value();
auto L3 = *L2->cloneByMultiplyingDuplicationFactor(2);
EXPECT_EQ(1U, L3->getBaseDiscriminator());
EXPECT_EQ(2U, L3->getDuplicationFactor());
EXPECT_EQ(L2, L2->cloneByMultiplyingDuplicationFactor(1).value());
EXPECT_EQ(L2, *L2->cloneByMultiplyingDuplicationFactor(1));
auto L4 = L3->cloneByMultiplyingDuplicationFactor(4).value();
auto L4 = *L3->cloneByMultiplyingDuplicationFactor(4);
EXPECT_EQ(1U, L4->getBaseDiscriminator());
EXPECT_EQ(8U, L4->getDuplicationFactor());
auto L5 = L4->cloneWithBaseDiscriminator(2).value();
auto L5 = *L4->cloneWithBaseDiscriminator(2);
EXPECT_EQ(2U, L5->getBaseDiscriminator());
EXPECT_EQ(8U, L5->getDuplicationFactor());
// Check extreme cases
auto L6 = L1->cloneWithBaseDiscriminator(0xfff).value();
auto L6 = *L1->cloneWithBaseDiscriminator(0xfff);
EXPECT_EQ(0xfffU, L6->getBaseDiscriminator());
EXPECT_EQ(0xfffU, L6->cloneByMultiplyingDuplicationFactor(0xfff)
.value()
EXPECT_EQ(0xfffU, (*L6->cloneByMultiplyingDuplicationFactor(0xfff))
->getDuplicationFactor());
// Check we return std::nullopt for unencodable cases.

View File

@ -271,7 +271,7 @@ TEST_F(VPIntrinsicTest, GetParamPos) {
std::optional<unsigned> MaskParamPos =
VPIntrinsic::getMaskParamPos(F.getIntrinsicID());
if (MaskParamPos) {
Type *MaskParamType = F.getArg(MaskParamPos.value())->getType();
Type *MaskParamType = F.getArg(*MaskParamPos)->getType();
ASSERT_TRUE(MaskParamType->isVectorTy());
ASSERT_TRUE(
cast<VectorType>(MaskParamType)->getElementType()->isIntegerTy(1));
@ -280,7 +280,7 @@ TEST_F(VPIntrinsicTest, GetParamPos) {
std::optional<unsigned> VecLenParamPos =
VPIntrinsic::getVectorLengthParamPos(F.getIntrinsicID());
if (VecLenParamPos) {
Type *VecLenParamType = F.getArg(VecLenParamPos.value())->getType();
Type *VecLenParamType = F.getArg(*VecLenParamPos)->getType();
ASSERT_TRUE(VecLenParamType->isIntegerTy(32));
}
}

View File

@ -49,7 +49,7 @@ TEST(ElfYamlTextAPI, YAMLReadableTBE) {
EXPECT_NE(Stub.get(), nullptr);
EXPECT_FALSE(Stub->SoName.has_value());
EXPECT_TRUE(Stub->Target.Arch.has_value());
EXPECT_EQ(Stub->Target.Arch.value(), (uint16_t)llvm::ELF::EM_X86_64);
EXPECT_EQ(*Stub->Target.Arch, (uint16_t)llvm::ELF::EM_X86_64);
EXPECT_EQ(Stub->NeededLibs.size(), 3u);
EXPECT_STREQ(Stub->NeededLibs[0].c_str(), "libc.so");
EXPECT_STREQ(Stub->NeededLibs[1].c_str(), "libfoo.so");

View File

@ -83,16 +83,16 @@ TEST(XCOFFObjectFileTest, XCOFFTracebackTableAPIGeneral) {
EXPECT_TRUE(TT.hasParmsOnStack());
ASSERT_TRUE(TT.getParmsType());
EXPECT_EQ(TT.getParmsType().value(), "i, f, d");
EXPECT_EQ(*TT.getParmsType(), "i, f, d");
ASSERT_TRUE(TT.getTraceBackTableOffset());
EXPECT_EQ(TT.getTraceBackTableOffset().value(), 64u);
EXPECT_EQ(*TT.getTraceBackTableOffset(), 64u);
EXPECT_FALSE(TT.getHandlerMask());
ASSERT_TRUE(TT.getFunctionName());
EXPECT_EQ(TT.getFunctionName().value(), "add_all");
EXPECT_EQ(TT.getFunctionName().value().size(), 7u);
EXPECT_EQ(*TT.getFunctionName(), "add_all");
EXPECT_EQ(TT.getFunctionName()->size(), 7u);
EXPECT_FALSE(TT.getAllocaRegister());
EXPECT_EQ(Size, 25u);
@ -171,11 +171,11 @@ TEST(XCOFFObjectFileTest, XCOFFTracebackTableAPIControlledStorageInfoDisp) {
XCOFFTracebackTable TT = *TTOrErr;
EXPECT_TRUE(TT.hasControlledStorage());
ASSERT_TRUE(TT.getNumOfCtlAnchors());
EXPECT_EQ(TT.getNumOfCtlAnchors().value(), 2u);
EXPECT_EQ(*TT.getNumOfCtlAnchors(), 2u);
ASSERT_TRUE(TT.getControlledStorageInfoDisp());
SmallVector<uint32_t, 8> Disp = TT.getControlledStorageInfoDisp().value();
SmallVector<uint32_t, 8> Disp = *TT.getControlledStorageInfoDisp();
ASSERT_EQ(Disp.size(), 2UL);
EXPECT_EQ(Disp[0], 0x05050000u);
@ -207,10 +207,10 @@ TEST(XCOFFObjectFileTest, XCOFFTracebackTableAPIHasVectorInfo) {
EXPECT_TRUE(TT.hasExtensionTable());
ASSERT_TRUE(TT.getParmsType());
EXPECT_EQ(TT.getParmsType().value(), "v, i, f, i, d, i, v");
EXPECT_EQ(*TT.getParmsType(), "v, i, f, i, d, i, v");
ASSERT_TRUE(TT.getVectorExt());
TBVectorExt VecExt = TT.getVectorExt().value();
TBVectorExt VecExt = *TT.getVectorExt();
EXPECT_EQ(VecExt.getNumberOfVRSaved(), 0);
EXPECT_TRUE(VecExt.isVRSavedOnStack());
@ -240,10 +240,10 @@ TEST(XCOFFObjectFileTest, XCOFFTracebackTableAPIHasVectorInfo1) {
XCOFFTracebackTable TT = *TTOrErr;
ASSERT_TRUE(TT.getParmsType());
EXPECT_EQ(TT.getParmsType().value(), "v, i, f, i, d, i, v, v");
EXPECT_EQ(*TT.getParmsType(), "v, i, f, i, d, i, v, v");
ASSERT_TRUE(TT.getVectorExt());
TBVectorExt VecExt = TT.getVectorExt().value();
TBVectorExt VecExt = *TT.getVectorExt();
EXPECT_EQ(VecExt.getNumberOfVRSaved(), 4);
EXPECT_FALSE(VecExt.isVRSavedOnStack());

View File

@ -92,7 +92,7 @@ debug_pubtypes:
ASSERT_THAT_ERROR(parseDWARFYAML(Yaml, Data), Succeeded());
ASSERT_TRUE(Data.PubNames.has_value());
DWARFYAML::PubSection PubNames = Data.PubNames.value();
DWARFYAML::PubSection PubNames = *Data.PubNames;
ASSERT_EQ(PubNames.Entries.size(), 2u);
EXPECT_EQ((uint32_t)PubNames.Entries[0].DieOffset, 0x1234u);
@ -101,7 +101,7 @@ debug_pubtypes:
EXPECT_EQ(PubNames.Entries[1].Name, "def");
ASSERT_TRUE(Data.PubTypes.has_value());
DWARFYAML::PubSection PubTypes = Data.PubTypes.value();
DWARFYAML::PubSection PubTypes = *Data.PubTypes;
ASSERT_EQ(PubTypes.Entries.size(), 2u);
EXPECT_EQ((uint32_t)PubTypes.Entries[0].DieOffset, 0x1234u);
@ -158,7 +158,7 @@ debug_gnu_pubtypes:
ASSERT_THAT_ERROR(parseDWARFYAML(Yaml, Data), Succeeded());
ASSERT_TRUE(Data.GNUPubNames.has_value());
DWARFYAML::PubSection GNUPubNames = Data.GNUPubNames.value();
DWARFYAML::PubSection GNUPubNames = *Data.GNUPubNames;
ASSERT_EQ(GNUPubNames.Entries.size(), 2u);
EXPECT_EQ((uint32_t)GNUPubNames.Entries[0].DieOffset, 0x1234u);
@ -169,7 +169,7 @@ debug_gnu_pubtypes:
EXPECT_EQ(GNUPubNames.Entries[1].Name, "def");
ASSERT_TRUE(Data.GNUPubTypes.has_value());
DWARFYAML::PubSection GNUPubTypes = Data.GNUPubTypes.value();
DWARFYAML::PubSection GNUPubTypes = *Data.GNUPubTypes;
ASSERT_EQ(GNUPubTypes.Entries.size(), 2u);
EXPECT_EQ((uint32_t)GNUPubTypes.Entries[0].DieOffset, 0x1234u);

View File

@ -104,9 +104,9 @@ MATCHER_P4(FrameContains, FunctionName, LineOffset, Column, Inline, "") {
*result_listener << "Hash mismatch";
return false;
}
if (F.SymbolName && F.SymbolName.value() != FunctionName) {
if (F.SymbolName && *F.SymbolName != FunctionName) {
*result_listener << "SymbolName mismatch\nWant: " << FunctionName
<< "\nGot: " << F.SymbolName.value();
<< "\nGot: " << *F.SymbolName;
return false;
}
if (F.LineOffset == LineOffset && F.Column == Column &&

View File

@ -36,5 +36,5 @@ TEST(Parser, SanityTest) {
Record *Foo = Records.getDef("Foo");
std::optional<StringRef> Field = Foo->getValueAsOptionalString("strField");
EXPECT_TRUE(Field.has_value());
EXPECT_EQ(Field.value(), "value");
EXPECT_EQ(*Field, "value");
}