Skip to content

Commit 757d9d2

Browse files
[lld] Use value_or instead of getValueOr (NFC)
1 parent 97c87c6 commit 757d9d2

9 files changed

+26
-27
lines changed

lld/ELF/LinkerScript.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ const Defined *LinkerScript::assignAddresses() {
12951295
if (script->hasSectionsCommand) {
12961296
// With a linker script, assignment of addresses to headers is covered by
12971297
// allocateHeaders().
1298-
dot = config->imageBase.getValueOr(0);
1298+
dot = config->imageBase.value_or(0);
12991299
} else {
13001300
// Assign addresses to headers right now.
13011301
dot = target->getImageBase();
@@ -1331,7 +1331,7 @@ SmallVector<PhdrEntry *, 0> LinkerScript::createPhdrs() {
13311331
// Process PHDRS and FILEHDR keywords because they are not
13321332
// real output sections and cannot be added in the following loop.
13331333
for (const PhdrsCommand &cmd : phdrsCommands) {
1334-
PhdrEntry *phdr = make<PhdrEntry>(cmd.type, cmd.flags.getValueOr(PF_R));
1334+
PhdrEntry *phdr = make<PhdrEntry>(cmd.type, cmd.flags.value_or(PF_R));
13351335

13361336
if (cmd.hasFilehdr)
13371337
phdr->add(Out::elfHeader);

lld/MachO/Config.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ struct PlatformInfo {
4343

4444
inline uint32_t encodeVersion(const llvm::VersionTuple &version) {
4545
return ((version.getMajor() << 020) |
46-
(version.getMinor().getValueOr(0) << 010) |
47-
version.getSubminor().getValueOr(0));
46+
(version.getMinor().value_or(0) << 010) |
47+
version.getSubminor().value_or(0));
4848
}
4949

5050
enum class NamespaceKind {

lld/wasm/Driver.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
581581

582582
static InputGlobal *createGlobal(StringRef name, bool isMutable) {
583583
llvm::wasm::WasmGlobal wasmGlobal;
584-
bool is64 = config->is64.getValueOr(false);
584+
bool is64 = config->is64.value_or(false);
585585
wasmGlobal.Type = {uint8_t(is64 ? WASM_TYPE_I64 : WASM_TYPE_I32), isMutable};
586586
wasmGlobal.InitExpr = intConst(0, is64);
587587
wasmGlobal.SymbolName = name;
@@ -616,11 +616,11 @@ static void createSyntheticSymbols() {
616616
"__wasm_call_ctors", WASM_SYMBOL_VISIBILITY_HIDDEN,
617617
make<SyntheticFunction>(nullSignature, "__wasm_call_ctors"));
618618

619-
bool is64 = config->is64.getValueOr(false);
619+
bool is64 = config->is64.value_or(false);
620620

621621
if (config->isPic) {
622622
WasmSym::stackPointer =
623-
createUndefinedGlobal("__stack_pointer", config->is64.getValueOr(false)
623+
createUndefinedGlobal("__stack_pointer", config->is64.value_or(false)
624624
? &mutableGlobalTypeI64
625625
: &mutableGlobalTypeI32);
626626
// For PIC code, we import two global variables (__memory_base and
@@ -672,7 +672,7 @@ static void createOptionalSymbols() {
672672
WasmSym::heapBase = symtab->addOptionalDataSymbol("__heap_base");
673673
WasmSym::definedMemoryBase = symtab->addOptionalDataSymbol("__memory_base");
674674
WasmSym::definedTableBase = symtab->addOptionalDataSymbol("__table_base");
675-
if (config->is64.getValueOr(false))
675+
if (config->is64.value_or(false))
676676
WasmSym::definedTableBase32 =
677677
symtab->addOptionalDataSymbol("__table_base32");
678678
}

lld/wasm/InputChunks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void InputChunk::generateRelocationCode(raw_ostream &os) const {
364364
LLVM_DEBUG(dbgs() << "generating runtime relocations: " << name
365365
<< " count=" << relocations.size() << "\n");
366366

367-
bool is64 = config->is64.getValueOr(false);
367+
bool is64 = config->is64.value_or(false);
368368
unsigned opcode_ptr_const = is64 ? WASM_OPCODE_I64_CONST
369369
: WASM_OPCODE_I32_CONST;
370370
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD

lld/wasm/InputElement.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class InputGlobal : public InputElement {
6464
const WasmInitExpr &getInitExpr() const { return initExpr; }
6565

6666
void setPointerValue(uint64_t value) {
67-
initExpr = intConst(value, config->is64.getValueOr(false));
67+
initExpr = intConst(value, config->is64.value_or(false));
6868
}
6969

7070
private:

lld/wasm/InputFiles.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void InputFile::checkArch(Triple::ArchType arch) const {
4747
if (is64 && !config->is64.hasValue()) {
4848
fatal(toString(this) +
4949
": must specify -mwasm64 to process wasm64 object files");
50-
} else if (config->is64.getValueOr(false) != is64) {
50+
} else if (config->is64.value_or(false) != is64) {
5151
fatal(toString(this) +
5252
": wasm32 object file can't be linked in wasm64 mode");
5353
}

lld/wasm/OutputSections.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void DataSection::finalizeContents() {
115115
writeUleb128(os, segmentCount, "data segment count");
116116
os.flush();
117117
bodySize = dataSectionHeader.size();
118-
bool is64 = config->is64.getValueOr(false);
118+
bool is64 = config->is64.value_or(false);
119119

120120
for (OutputSegment *segment : segments) {
121121
if (!segment->requiredInBinary())

lld/wasm/SyntheticSections.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void DylinkSection::writeBody() {
124124

125125
for (const Symbol *sym : importInfo) {
126126
LLVM_DEBUG(llvm::dbgs() << "imports info: " << toString(*sym) << "\n");
127-
StringRef module = sym->importModule.getValueOr(defaultModule);
128-
StringRef name = sym->importName.getValueOr(sym->getName());
127+
StringRef module = sym->importModule.value_or(defaultModule);
128+
StringRef name = sym->importName.value_or(sym->getName());
129129
writeStr(sub.os, module, "import module");
130130
writeStr(sub.os, name, "import name");
131131
writeUleb128(sub.os, sym->flags, "sym flags");
@@ -184,8 +184,8 @@ void ImportSection::addGOTEntry(Symbol *sym) {
184184

185185
void ImportSection::addImport(Symbol *sym) {
186186
assert(!isSealed);
187-
StringRef module = sym->importModule.getValueOr(defaultModule);
188-
StringRef name = sym->importName.getValueOr(sym->getName());
187+
StringRef module = sym->importModule.value_or(defaultModule);
188+
StringRef name = sym->importName.value_or(sym->getName());
189189
if (auto *f = dyn_cast<FunctionSymbol>(sym)) {
190190
ImportKey<WasmSignature> key(*(f->getSignature()), module, name);
191191
auto entry = importedFunctions.try_emplace(key, numImportedFunctions);
@@ -232,7 +232,7 @@ void ImportSection::writeBody() {
232232

233233
writeUleb128(os, getNumImports(), "import count");
234234

235-
bool is64 = config->is64.getValueOr(false);
235+
bool is64 = config->is64.value_or(false);
236236

237237
if (config->importMemory) {
238238
WasmImport import;
@@ -254,8 +254,8 @@ void ImportSection::writeBody() {
254254

255255
for (const Symbol *sym : importedSymbols) {
256256
WasmImport import;
257-
import.Field = sym->importName.getValueOr(sym->getName());
258-
import.Module = sym->importModule.getValueOr(defaultModule);
257+
import.Field = sym->importName.value_or(sym->getName());
258+
import.Module = sym->importModule.value_or(defaultModule);
259259

260260
if (auto *functionSym = dyn_cast<FunctionSymbol>(sym)) {
261261
import.Kind = WASM_EXTERNAL_FUNCTION;
@@ -357,7 +357,7 @@ void MemorySection::writeBody() {
357357
flags |= WASM_LIMITS_FLAG_HAS_MAX;
358358
if (config->sharedMemory)
359359
flags |= WASM_LIMITS_FLAG_IS_SHARED;
360-
if (config->is64.getValueOr(false))
360+
if (config->is64.value_or(false))
361361
flags |= WASM_LIMITS_FLAG_IS_64;
362362
writeUleb128(os, flags, "memory limits flags");
363363
writeUleb128(os, numMemoryPages, "initial pages");
@@ -415,7 +415,7 @@ void GlobalSection::addInternalGOTEntry(Symbol *sym) {
415415

416416
void GlobalSection::generateRelocationCode(raw_ostream &os, bool TLS) const {
417417
assert(!config->extendedConst);
418-
bool is64 = config->is64.getValueOr(false);
418+
bool is64 = config->is64.value_or(false);
419419
unsigned opcode_ptr_const = is64 ? WASM_OPCODE_I64_CONST
420420
: WASM_OPCODE_I32_CONST;
421421
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD
@@ -465,7 +465,7 @@ void GlobalSection::writeBody() {
465465
writeGlobalType(os, g->getType());
466466
writeInitExpr(os, g->getInitExpr());
467467
}
468-
bool is64 = config->is64.getValueOr(false);
468+
bool is64 = config->is64.value_or(false);
469469
uint8_t itype = is64 ? WASM_TYPE_I64 : WASM_TYPE_I32;
470470
for (const Symbol *sym : internalGotSymbols) {
471471
bool mutable_ = false;
@@ -569,8 +569,8 @@ void ElemSection::writeBody() {
569569
if (config->isPic) {
570570
initExpr.Inst.Opcode = WASM_OPCODE_GLOBAL_GET;
571571
initExpr.Inst.Value.Global =
572-
(config->is64.getValueOr(false) ? WasmSym::tableBase32
573-
: WasmSym::tableBase)
572+
(config->is64.value_or(false) ? WasmSym::tableBase32
573+
: WasmSym::tableBase)
574574
->getGlobalIndex();
575575
} else {
576576
initExpr.Inst.Opcode = WASM_OPCODE_I32_CONST;

lld/wasm/Writer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ void Writer::layoutMemory() {
328328
WasmSym::heapBase->setVA(memoryPtr);
329329
}
330330

331-
uint64_t maxMemorySetting = 1ULL
332-
<< (config->is64.getValueOr(false) ? 48 : 32);
331+
uint64_t maxMemorySetting = 1ULL << (config->is64.value_or(false) ? 48 : 32);
333332

334333
if (config->initialMemory != 0) {
335334
if (config->initialMemory != alignTo(config->initialMemory, WasmPageSize))
@@ -1057,7 +1056,7 @@ void Writer::createInitMemoryFunction() {
10571056
assert(WasmSym::initMemoryFlag);
10581057
flagAddress = WasmSym::initMemoryFlag->getVA();
10591058
}
1060-
bool is64 = config->is64.getValueOr(false);
1059+
bool is64 = config->is64.value_or(false);
10611060
std::string bodyContent;
10621061
{
10631062
raw_string_ostream os(bodyContent);

0 commit comments

Comments
 (0)