[lld][WebAssembly] clang-format lld/wasm files. NFC (#181871)

This was originally done back in 2018 in 4821ebf73, and things seem to
have strayed a little since then.

I noticed this while reviewing #175800.
This commit is contained in:
Sam Clegg 2026-02-17 11:44:08 -08:00 committed by GitHub
parent 98c76d3643
commit 42618de278
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 53 additions and 52 deletions

View File

@ -885,7 +885,7 @@ static void writeWhyExtract() {
// Equivalent of demote demoteSharedAndLazySymbols() in the ELF linker
static void demoteLazySymbols() {
for (Symbol *sym : symtab->symbols()) {
if (auto* s = dyn_cast<LazySymbol>(sym)) {
if (auto *s = dyn_cast<LazySymbol>(sym)) {
if (s->signature) {
LLVM_DEBUG(llvm::dbgs()
<< "demoting lazy func: " << s->getName() << "\n");
@ -1026,15 +1026,15 @@ static void processStubLibrariesPreLTO() {
for (auto &stub_file : ctx.stubFiles) {
LLVM_DEBUG(llvm::dbgs()
<< "processing stub file: " << stub_file->getName() << "\n");
for (auto [name, deps]: stub_file->symbolDependencies) {
auto* sym = symtab->find(name);
for (auto [name, deps] : stub_file->symbolDependencies) {
auto *sym = symtab->find(name);
// If the symbol is not present at all (yet), or if it is present but
// undefined, then mark the dependent symbols as used by a regular
// object so they will be preserved and exported by the LTO process.
if (!sym || sym->isUndefined()) {
for (const auto dep : deps) {
auto* needed = symtab->find(dep);
if (needed ) {
auto *needed = symtab->find(dep);
if (needed) {
needed->isUsedInRegularObj = true;
// Like with handleLibcall we have to extract any LTO archive
// members that might need to be exported due to stub library
@ -1106,8 +1106,8 @@ static void processStubLibraries() {
// First look for any imported symbols that directly match
// the names of the stub imports
for (auto [name, deps]: stub_file->symbolDependencies) {
auto* sym = symtab->find(name);
for (auto [name, deps] : stub_file->symbolDependencies) {
auto *sym = symtab->find(name);
if (sym && sym->isUndefined() && sym->isUsedInRegularObj) {
depsAdded |= addStubSymbolDeps(stub_file, sym, deps);
} else {

View File

@ -423,8 +423,7 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
bool is64 = ctx.arg.is64.value_or(false);
bool generated = false;
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD
: WASM_OPCODE_I32_ADD;
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD : WASM_OPCODE_I32_ADD;
uint64_t tombstone = getTombstone();
// TODO(sbc): Encode the relocations in the data section and write a loop
@ -585,12 +584,12 @@ uint64_t InputSection::getTombstoneForSection(StringRef name) {
return UINT64_C(-2);
if (name.starts_with(".debug_"))
return UINT64_C(-1);
// If the function occurs in an function attribute section change it to -1 since
// 0 is a valid function index.
// If the function occurs in an function attribute section change it to -1
// since 0 is a valid function index.
if (name.starts_with("llvm.func_attr."))
return UINT64_C(-1);
// Returning 0 means there is no tombstone value for this section, and relocation
// will just use the addend.
// Returning 0 means there is no tombstone value for this section, and
// relocation will just use the addend.
return 0;
}

View File

@ -143,7 +143,7 @@ int64_t ObjFile::calcNewAddend(const WasmRelocation &reloc) const {
// Translate from the relocation's index into the final linked output value.
uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone,
const InputChunk *chunk) const {
const Symbol* sym = nullptr;
const Symbol *sym = nullptr;
if (reloc.Type != R_WASM_TYPE_INDEX_LEB) {
sym = symbols[reloc.Index];
@ -562,7 +562,6 @@ void ObjFile::parse(bool ignoreComdats) {
typeMap.resize(getWasmObj()->types().size());
typeIsUsed.resize(getWasmObj()->types().size(), false);
// Populate `Segments`.
for (const WasmSegment &s : wasmObj->dataSegments()) {
InputChunk *seg;
@ -886,7 +885,8 @@ void BitcodeFile::parseLazy() {
void BitcodeFile::parse(StringRef symName) {
if (doneLTO) {
error(toString(this) + ": attempt to add bitcode file after LTO (" + symName + ")");
error(toString(this) + ": attempt to add bitcode file after LTO (" +
symName + ")");
return;
}

View File

@ -33,7 +33,7 @@ static bool requiresGOTAccess(const Symbol *sym) {
return true;
}
static bool allowUndefined(const Symbol* sym) {
static bool allowUndefined(const Symbol *sym) {
// Symbols that are explicitly imported are always allowed to be undefined at
// link time.
if (sym->isImported())

View File

@ -101,7 +101,7 @@ Symbol *SymbolTable::find(StringRef name) {
return symVector[it->second];
}
void SymbolTable::replace(StringRef name, Symbol* sym) {
void SymbolTable::replace(StringRef name, Symbol *sym) {
auto it = symMap.find(CachedHashStringRef(name));
symVector[it->second] = sym;
}
@ -224,8 +224,8 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef name,
LLVM_DEBUG(dbgs() << "addSyntheticFunction: " << name << "\n");
assert(!find(name));
ctx.syntheticFunctions.emplace_back(function);
return replaceSymbol<DefinedFunction>(insertName(name).first, name,
flags, nullptr, function);
return replaceSymbol<DefinedFunction>(insertName(name).first, name, flags,
nullptr, function);
}
// Adds an optional, linker generated, data symbol. The symbol will only be
@ -439,7 +439,8 @@ Symbol *SymbolTable::addDefinedFunction(StringRef name, uint32_t flags,
// If the new defined function doesn't have signature (i.e. bitcode
// functions) but the old symbol does, then preserve the old signature
const WasmSignature *oldSig = s->getSignature();
auto* newSym = replaceSymbol<DefinedFunction>(sym, name, flags, file, function);
auto *newSym =
replaceSymbol<DefinedFunction>(sym, name, flags, file, function);
if (!newSym->signature)
newSym->signature = oldSig;
};
@ -459,8 +460,9 @@ Symbol *SymbolTable::addDefinedFunction(StringRef name, uint32_t flags,
if (auto ud = dyn_cast<UndefinedFunction>(existingFunction))
checkSig = ud->isCalledDirectly;
if (checkSig && function && !signatureMatches(existingFunction, &function->signature)) {
Symbol* variant;
if (checkSig && function &&
!signatureMatches(existingFunction, &function->signature)) {
Symbol *variant;
if (getFunctionVariant(s, &function->signature, file, &variant))
// New variant, always replace
replaceSym(variant);
@ -909,7 +911,7 @@ bool SymbolTable::addComdat(StringRef name) {
// The new signature doesn't match. Create a variant to the symbol with the
// signature encoded in the name and return that instead. These symbols are
// then unified later in handleSymbolVariants.
bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig,
bool SymbolTable::getFunctionVariant(Symbol *sym, const WasmSignature *sig,
const InputFile *file, Symbol **out) {
LLVM_DEBUG(dbgs() << "getFunctionVariant: " << sym->getName() << " -> "
<< " " << toString(*sig) << "\n");
@ -921,7 +923,7 @@ bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig,
if (variants.empty())
variants.push_back(sym);
for (Symbol* v : variants) {
for (Symbol *v : variants) {
if (*v->getSignature() == *sig) {
variant = v;
break;
@ -940,7 +942,8 @@ bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig,
variant->forceExport = false;
variants.push_back(variant);
} else {
LLVM_DEBUG(dbgs() << "variant already exists: " << toString(*variant) << "\n");
LLVM_DEBUG(dbgs() << "variant already exists: " << toString(*variant)
<< "\n");
assert(*variant->getSignature() == *sig);
}
@ -957,7 +960,7 @@ void SymbolTable::trace(StringRef name) {
void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) {
// Swap symbols as instructed by -wrap.
int &origIdx = symMap[CachedHashStringRef(sym->getName())];
int &realIdx= symMap[CachedHashStringRef(real->getName())];
int &realIdx = symMap[CachedHashStringRef(real->getName())];
int &wrapIdx = symMap[CachedHashStringRef(wrap->getName())];
LLVM_DEBUG(dbgs() << "wrap: " << sym->getName() << "\n");
@ -1049,7 +1052,7 @@ void SymbolTable::handleSymbolVariants() {
#ifndef NDEBUG
LLVM_DEBUG(dbgs() << "symbol with (" << variants.size()
<< ") variants: " << symName << "\n");
for (auto *s: variants) {
for (auto *s : variants) {
auto *f = cast<FunctionSymbol>(s);
LLVM_DEBUG(dbgs() << " variant: " + f->getName() << " "
<< toString(*f->signature) << "\n");
@ -1087,4 +1090,4 @@ void SymbolTable::handleSymbolVariants() {
}
}
} // namespace wasm::lld
} // namespace lld::wasm

View File

@ -46,7 +46,7 @@ public:
Symbol *find(StringRef name);
void replace(StringRef name, Symbol* sym);
void replace(StringRef name, Symbol *sym);
void trace(StringRef name);
@ -108,7 +108,7 @@ private:
std::pair<Symbol *, bool> insert(StringRef name, const InputFile *file);
std::pair<Symbol *, bool> insertName(StringRef name);
bool getFunctionVariant(Symbol* sym, const WasmSignature *sig,
bool getFunctionVariant(Symbol *sym, const WasmSignature *sig,
const InputFile *file, Symbol **out);
InputFunction *replaceWithUnreachable(Symbol *sym, const WasmSignature &sig,
StringRef debugName);

View File

@ -95,7 +95,7 @@ WasmSymbolType Symbol::getWasmType() const {
}
const WasmSignature *Symbol::getSignature() const {
if (auto* f = dyn_cast<FunctionSymbol>(this))
if (auto *f = dyn_cast<FunctionSymbol>(this))
return f->signature;
if (auto *t = dyn_cast<TagSymbol>(this))
return t->signature;
@ -223,9 +223,7 @@ bool Symbol::isExportedExplicit() const {
return forceExport || flags & WASM_SYMBOL_EXPORTED;
}
bool Symbol::isNoStrip() const {
return flags & WASM_SYMBOL_NO_STRIP;
}
bool Symbol::isNoStrip() const { return flags & WASM_SYMBOL_NO_STRIP; }
uint32_t FunctionSymbol::getFunctionIndex() const {
if (const auto *u = dyn_cast<UndefinedFunction>(this))
@ -413,7 +411,7 @@ void LazySymbol::setWeak() {
flags |= (flags & ~WASM_SYMBOL_BINDING_MASK) | WASM_SYMBOL_BINDING_WEAK;
}
void printTraceSymbolUndefined(StringRef name, const InputFile* file) {
void printTraceSymbolUndefined(StringRef name, const InputFile *file) {
message(toString(file) + ": reference to " + name);
}

View File

@ -127,7 +127,7 @@ public:
// or similar.
bool isNoStrip() const;
const WasmSignature* getSignature() const;
const WasmSignature *getSignature() const;
uint32_t getGOTIndex() const {
assert(gotIndex != INVALID_INDEX);
@ -561,10 +561,10 @@ union SymbolUnion {
static_assert(sizeof(SymbolUnion) <= 120, "SymbolUnion too large");
void printTraceSymbol(Symbol *sym);
void printTraceSymbolUndefined(StringRef name, const InputFile* file);
void printTraceSymbolUndefined(StringRef name, const InputFile *file);
template <typename T, typename... ArgT>
T *replaceSymbol(Symbol *s, ArgT &&... arg) {
T *replaceSymbol(Symbol *s, ArgT &&...arg) {
static_assert(std::is_trivially_destructible<T>(),
"Symbol types must be trivially destructible");
static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small");

View File

@ -466,8 +466,7 @@ void GlobalSection::addInternalGOTEntry(Symbol *sym) {
void GlobalSection::generateRelocationCode(raw_ostream &os, bool TLS) const {
assert(!ctx.arg.extendedConst);
bool is64 = ctx.arg.is64.value_or(false);
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD
: WASM_OPCODE_I32_ADD;
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD : WASM_OPCODE_I32_ADD;
for (const Symbol *sym : internalGotSymbols) {
if (TLS != sym->isTLS())
@ -646,7 +645,7 @@ void ElemSection::writeBody() {
uint32_t tableIndex = ctx.arg.tableBase;
for (const FunctionSymbol *sym : indirectFunctions) {
assert(sym->getTableIndex() == tableIndex);
(void) tableIndex;
(void)tableIndex;
writeUleb128(os, sym->getFunctionIndex(), "function index");
++tableIndex;
}
@ -992,4 +991,4 @@ void BuildIdSection::writeBuildId(llvm::ArrayRef<uint8_t> buf) {
memcpy(hashPlaceholderPtr, buf.data(), hashSize);
}
} // namespace wasm::lld
} // namespace lld::wasm

View File

@ -125,7 +125,7 @@ inline bool operator==(const ImportKey<T> &lhs, const ImportKey<T> &rhs) {
lhs.importName == rhs.importName && lhs.type == rhs.type;
}
} // namespace wasm::lld
} // namespace lld::wasm
// `ImportKey<T>` can be used as a key in a `DenseMap` if `T` can be used as a
// key in a `DenseMap`.
@ -324,8 +324,7 @@ public:
class ElemSection : public SyntheticSection {
public:
ElemSection()
: SyntheticSection(llvm::wasm::WASM_SEC_ELEM) {}
ElemSection() : SyntheticSection(llvm::wasm::WASM_SEC_ELEM) {}
bool isNeeded() const override { return indirectFunctions.size() > 0; };
void writeBody() override;
void addEntry(FunctionSymbol *sym);

View File

@ -311,7 +311,8 @@ void Writer::writeBuildId() {
}
static void setGlobalPtr(DefinedGlobal *g, uint64_t memoryPtr) {
LLVM_DEBUG(dbgs() << "setGlobalPtr " << g->getName() << " -> " << memoryPtr << "\n");
LLVM_DEBUG(dbgs() << "setGlobalPtr " << g->getName() << " -> " << memoryPtr
<< "\n");
g->global->setPointerValue(memoryPtr);
}
@ -358,7 +359,8 @@ void Writer::layoutMemory() {
placeStack();
if (ctx.arg.globalBase) {
if (ctx.arg.globalBase < memoryPtr) {
error("--global-base cannot be less than stack size when --stack-first is used");
error("--global-base cannot be less than stack size when --stack-first "
"is used");
return;
}
memoryPtr = ctx.arg.globalBase;
@ -1183,7 +1185,7 @@ void Writer::createSyntheticInitFunctions() {
auto hasTLSRelocs = [](const OutputSegment *segment) {
if (segment->isTLS())
for (const auto* is: segment->inputSegments)
for (const auto *is : segment->inputSegments)
if (is->getRelocations().size())
return true;
return false;
@ -1635,7 +1637,8 @@ void Writer::createInitTLSFunction() {
writeU8(os, WASM_OPCODE_GLOBAL_SET, "global.set");
writeUleb128(os, ctx.sym.tlsBase->getGlobalIndex(), "global index");
// FIXME(wvo): this local needs to be I64 in wasm64, or we need an extend op.
// FIXME(wvo): this local needs to be I64 in wasm64, or we need an extend
// op.
writeU8(os, WASM_OPCODE_LOCAL_GET, "local.get");
writeUleb128(os, 0, "local index");
@ -1901,4 +1904,4 @@ void Writer::createHeader() {
void writeResult() { Writer().run(); }
} // namespace wasm::lld
} // namespace lld::wasm

View File

@ -97,7 +97,7 @@ void writeSleb128(raw_ostream &os, int64_t number, const Twine &msg) {
}
void writeBytes(raw_ostream &os, const char *bytes, size_t count,
const Twine &msg) {
const Twine &msg) {
debugWrite(os.tell(), msg + " [data[" + Twine(count) + "]]");
os.write(bytes, count);
}