[lld] [lld][WebAssembly] clang-format lld/wasm files. NFC (PR #181871)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 17 09:47:22 PST 2026
https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/181871
This was originally done back in 2018 in 4821ebf73, and things seem to have strayed a little since then.
>From bdfcbeb2b2c889b0bdbe2d7303b8288dbabf2a4c Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Tue, 17 Feb 2026 09:44:34 -0800
Subject: [PATCH] [lld][WebAssembly] clang-format lld/wasm files. NFC
This was originally done back in 2018 in 4821ebf73, and things seem
to have strayed a little since then.
---
lld/wasm/Driver.cpp | 14 +++++++-------
lld/wasm/InputChunks.cpp | 11 +++++------
lld/wasm/InputFiles.cpp | 6 +++---
lld/wasm/Relocations.cpp | 2 +-
lld/wasm/SymbolTable.cpp | 27 +++++++++++++++------------
lld/wasm/SymbolTable.h | 4 ++--
lld/wasm/Symbols.cpp | 8 +++-----
lld/wasm/Symbols.h | 6 +++---
lld/wasm/SyntheticSections.cpp | 7 +++----
lld/wasm/SyntheticSections.h | 5 ++---
lld/wasm/Writer.cpp | 13 ++++++++-----
lld/wasm/WriterUtils.cpp | 2 +-
12 files changed, 53 insertions(+), 52 deletions(-)
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index b1e36f2ecff74..508c6b9df90bd 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -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 {
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp
index 14e02e6009318..79bac5f444405 100644
--- a/lld/wasm/InputChunks.cpp
+++ b/lld/wasm/InputChunks.cpp
@@ -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;
}
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 5e59b3af83f95..dcdd138508c1e 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -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;
}
diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index a3f87ea3d69c0..a1840abe88b3a 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -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())
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index 011e4341519cd..9bd93f317c3c5 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -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
diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h
index 5d09d8b685716..649614298c52b 100644
--- a/lld/wasm/SymbolTable.h
+++ b/lld/wasm/SymbolTable.h
@@ -46,7 +46,7 @@ class SymbolTable {
Symbol *find(StringRef name);
- void replace(StringRef name, Symbol* sym);
+ void replace(StringRef name, Symbol *sym);
void trace(StringRef name);
@@ -108,7 +108,7 @@ class SymbolTable {
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);
diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp
index f2040441e6257..97a9871a06308 100644
--- a/lld/wasm/Symbols.cpp
+++ b/lld/wasm/Symbols.cpp
@@ -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);
}
diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h
index 55ee21939ce07..3dda36f88d5e3 100644
--- a/lld/wasm/Symbols.h
+++ b/lld/wasm/Symbols.h
@@ -127,7 +127,7 @@ class Symbol {
// 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");
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index ede6ac4da77b3..81d4b0327c447 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -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
diff --git a/lld/wasm/SyntheticSections.h b/lld/wasm/SyntheticSections.h
index 313cbd63ecbf2..2862b22da86b3 100644
--- a/lld/wasm/SyntheticSections.h
+++ b/lld/wasm/SyntheticSections.h
@@ -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 @@ class StartSection : public SyntheticSection {
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);
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index dfd856f2faee6..128931513b215 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -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
diff --git a/lld/wasm/WriterUtils.cpp b/lld/wasm/WriterUtils.cpp
index a23d0febb364f..fee25a7255793 100644
--- a/lld/wasm/WriterUtils.cpp
+++ b/lld/wasm/WriterUtils.cpp
@@ -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);
}
More information about the llvm-commits
mailing list