Skip to content

Commit f77bbc0

Browse files
authored
[WebAssembly] Apply clang-tidy fixes on AsmParser/TypeCheck (NFC) (#109692)
Fixes are mostly one of these: - `auto` -> `auto *` when the type is a pointer - Function names start with a lowercase letter - Variable names start with an uppercase letter - No need to have an `else` after a `return` Diff without whitespaces is easier to view.
1 parent 3bb92b5 commit f77bbc0

File tree

3 files changed

+59
-61
lines changed

3 files changed

+59
-61
lines changed

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -204,20 +204,20 @@ struct WebAssemblyOperand : public MCParsedAsmOperand {
204204
};
205205

206206
// Perhaps this should go somewhere common.
207-
static wasm::WasmLimits DefaultLimits() {
207+
static wasm::WasmLimits defaultLimits() {
208208
return {wasm::WASM_LIMITS_FLAG_NONE, 0, 0};
209209
}
210210

211-
static MCSymbolWasm *GetOrCreateFunctionTableSymbol(MCContext &Ctx,
211+
static MCSymbolWasm *getOrCreateFunctionTableSymbol(MCContext &Ctx,
212212
const StringRef &Name,
213-
bool is64) {
213+
bool Is64) {
214214
MCSymbolWasm *Sym = cast_or_null<MCSymbolWasm>(Ctx.lookupSymbol(Name));
215215
if (Sym) {
216216
if (!Sym->isFunctionTable())
217217
Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table");
218218
} else {
219219
Sym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(Name));
220-
Sym->setFunctionTable(is64);
220+
Sym->setFunctionTable(Is64);
221221
// The default function table is synthesized by the linker.
222222
Sym->setUndefined();
223223
}
@@ -265,7 +265,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
265265
MCSymbolWasm *DefaultFunctionTable = nullptr;
266266
MCSymbol *LastFunctionLabel = nullptr;
267267

268-
bool is64;
268+
bool Is64;
269269

270270
WebAssemblyAsmTypeCheck TC;
271271
// Don't type check if -no-type-check was set.
@@ -275,8 +275,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
275275
WebAssemblyAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser,
276276
const MCInstrInfo &MII, const MCTargetOptions &Options)
277277
: MCTargetAsmParser(Options, STI, MII), Parser(Parser),
278-
Lexer(Parser.getLexer()), is64(STI.getTargetTriple().isArch64Bit()),
279-
TC(Parser, MII, is64), SkipTypeCheck(Options.MCNoTypeCheck) {
278+
Lexer(Parser.getLexer()), Is64(STI.getTargetTriple().isArch64Bit()),
279+
TC(Parser, MII, Is64), SkipTypeCheck(Options.MCNoTypeCheck) {
280280
setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
281281
// Don't type check if this is inline asm, since that is a naked sequence of
282282
// instructions without a function/locals decl.
@@ -290,8 +290,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
290290
void Initialize(MCAsmParser &Parser) override {
291291
MCAsmParserExtension::Initialize(Parser);
292292

293-
DefaultFunctionTable = GetOrCreateFunctionTableSymbol(
294-
getContext(), "__indirect_function_table", is64);
293+
DefaultFunctionTable = getOrCreateFunctionTableSymbol(
294+
getContext(), "__indirect_function_table", Is64);
295295
if (!STI->checkFeatures("+reference-types"))
296296
DefaultFunctionTable->setOmitFromLinkingSection();
297297
}
@@ -538,28 +538,26 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
538538
auto &Tok = Lexer.getTok();
539539
if (Tok.is(AsmToken::Identifier)) {
540540
auto *Sym =
541-
GetOrCreateFunctionTableSymbol(getContext(), Tok.getString(), is64);
541+
getOrCreateFunctionTableSymbol(getContext(), Tok.getString(), Is64);
542542
const auto *Val = MCSymbolRefExpr::create(Sym, getContext());
543543
*Op = std::make_unique<WebAssemblyOperand>(
544544
Tok.getLoc(), Tok.getEndLoc(), WebAssemblyOperand::SymOp{Val});
545545
Parser.Lex();
546546
return expect(AsmToken::Comma, ",");
547-
} else {
548-
const auto *Val =
549-
MCSymbolRefExpr::create(DefaultFunctionTable, getContext());
550-
*Op = std::make_unique<WebAssemblyOperand>(
551-
SMLoc(), SMLoc(), WebAssemblyOperand::SymOp{Val});
552-
return false;
553547
}
554-
} else {
555-
// For the MVP there is at most one table whose number is 0, but we can't
556-
// write a table symbol or issue relocations. Instead we just ensure the
557-
// table is live and write a zero.
558-
getStreamer().emitSymbolAttribute(DefaultFunctionTable, MCSA_NoDeadStrip);
559-
*Op = std::make_unique<WebAssemblyOperand>(SMLoc(), SMLoc(),
560-
WebAssemblyOperand::IntOp{0});
548+
const auto *Val =
549+
MCSymbolRefExpr::create(DefaultFunctionTable, getContext());
550+
*Op = std::make_unique<WebAssemblyOperand>(
551+
SMLoc(), SMLoc(), WebAssemblyOperand::SymOp{Val});
561552
return false;
562553
}
554+
// For the MVP there is at most one table whose number is 0, but we can't
555+
// write a table symbol or issue relocations. Instead we just ensure the
556+
// table is live and write a zero.
557+
getStreamer().emitSymbolAttribute(DefaultFunctionTable, MCSA_NoDeadStrip);
558+
*Op = std::make_unique<WebAssemblyOperand>(SMLoc(), SMLoc(),
559+
WebAssemblyOperand::IntOp{0});
560+
return false;
563561
}
564562

565563
bool parseInstruction(ParseInstructionInfo & /*Info*/, StringRef Name,
@@ -674,7 +672,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
674672
// expects to be able to recreate the actual unique-ified type indices.
675673
auto &Ctx = getContext();
676674
auto Loc = Parser.getTok();
677-
auto Signature = Ctx.createWasmSignature();
675+
auto *Signature = Ctx.createWasmSignature();
678676
if (parseSignature(Signature))
679677
return true;
680678
// Got signature as block type, don't need more
@@ -879,9 +877,9 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
879877
return false;
880878
}
881879

882-
bool CheckDataSection() {
880+
bool checkDataSection() {
883881
if (CurrentState != DataSection) {
884-
auto WS = cast<MCSectionWasm>(getStreamer().getCurrentSectionOnly());
882+
auto *WS = cast<MCSectionWasm>(getStreamer().getCurrentSectionOnly());
885883
if (WS && WS->isText())
886884
return error("data directive must occur in a data segment: ",
887885
Lexer.getTok());
@@ -929,7 +927,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
929927
return error("Unknown type in .globaltype modifier: ", TypeTok);
930928
}
931929
// Now set this symbol with the correct type.
932-
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
930+
auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
933931
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
934932
WasmSym->setGlobalType(wasm::WasmGlobalType{uint8_t(*Type), Mutable});
935933
// And emit the directive again.
@@ -954,15 +952,15 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
954952
if (!ElemType)
955953
return error("Unknown type in .tabletype directive: ", ElemTypeTok);
956954

957-
wasm::WasmLimits Limits = DefaultLimits();
955+
wasm::WasmLimits Limits = defaultLimits();
958956
if (isNext(AsmToken::Comma) && parseLimits(&Limits))
959957
return ParseStatus::Failure;
960958

961959
// Now that we have the name and table type, we can actually create the
962960
// symbol
963-
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
961+
auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
964962
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
965-
if (is64) {
963+
if (Is64) {
966964
Limits.Flags |= wasm::WASM_LIMITS_FLAG_IS_64;
967965
}
968966
wasm::WasmTableType Type = {*ElemType, Limits};
@@ -980,7 +978,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
980978
auto SymName = expectIdent();
981979
if (SymName.empty())
982980
return ParseStatus::Failure;
983-
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
981+
auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
984982
if (WasmSym->isDefined()) {
985983
// We push 'Function' either when a label is parsed or a .functype
986984
// directive is parsed. The reason it is not easy to do this uniformly
@@ -1001,7 +999,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
1001999
CurrentState = FunctionStart;
10021000
LastFunctionLabel = WasmSym;
10031001
}
1004-
auto Signature = Ctx.createWasmSignature();
1002+
auto *Signature = Ctx.createWasmSignature();
10051003
if (parseSignature(Signature))
10061004
return ParseStatus::Failure;
10071005
TC.funcDecl(*Signature);
@@ -1021,7 +1019,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
10211019
auto ExportName = expectIdent();
10221020
if (ExportName.empty())
10231021
return ParseStatus::Failure;
1024-
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
1022+
auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
10251023
WasmSym->setExportName(Ctx.allocateString(ExportName));
10261024
TOut.emitExportName(WasmSym, ExportName);
10271025
return expect(AsmToken::EndOfStatement, "EOL");
@@ -1036,7 +1034,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
10361034
auto ImportModule = expectIdent();
10371035
if (ImportModule.empty())
10381036
return ParseStatus::Failure;
1039-
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
1037+
auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
10401038
WasmSym->setImportModule(Ctx.allocateString(ImportModule));
10411039
TOut.emitImportModule(WasmSym, ImportModule);
10421040
return expect(AsmToken::EndOfStatement, "EOL");
@@ -1051,7 +1049,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
10511049
auto ImportName = expectIdent();
10521050
if (ImportName.empty())
10531051
return ParseStatus::Failure;
1054-
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
1052+
auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
10551053
WasmSym->setImportName(Ctx.allocateString(ImportName));
10561054
TOut.emitImportName(WasmSym, ImportName);
10571055
return expect(AsmToken::EndOfStatement, "EOL");
@@ -1061,8 +1059,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
10611059
auto SymName = expectIdent();
10621060
if (SymName.empty())
10631061
return ParseStatus::Failure;
1064-
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
1065-
auto Signature = Ctx.createWasmSignature();
1062+
auto *WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
1063+
auto *Signature = Ctx.createWasmSignature();
10661064
if (parseRegTypeList(Signature->Params))
10671065
return ParseStatus::Failure;
10681066
WasmSym->setSignature(Signature);
@@ -1089,7 +1087,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
10891087
DirectiveID.getString() == ".int16" ||
10901088
DirectiveID.getString() == ".int32" ||
10911089
DirectiveID.getString() == ".int64") {
1092-
if (CheckDataSection())
1090+
if (checkDataSection())
10931091
return ParseStatus::Failure;
10941092
const MCExpr *Val;
10951093
SMLoc End;
@@ -1102,7 +1100,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
11021100
}
11031101

11041102
if (DirectiveID.getString() == ".asciz") {
1105-
if (CheckDataSection())
1103+
if (checkDataSection())
11061104
return ParseStatus::Failure;
11071105
std::string S;
11081106
if (Parser.parseEscapedString(S))
@@ -1146,7 +1144,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
11461144
if (Op0.getImm() == -1)
11471145
Op0.setImm(Align);
11481146
}
1149-
if (is64) {
1147+
if (Is64) {
11501148
// Upgrade 32-bit loads/stores to 64-bit. These mostly differ by having
11511149
// an offset64 arg instead of offset32, but to the assembler matcher
11521150
// they're both immediates so don't get selected for.
@@ -1171,9 +1169,9 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
11711169
SmallString<128> Message;
11721170
raw_svector_ostream OS(Message);
11731171
OS << "instruction requires:";
1174-
for (unsigned i = 0, e = MissingFeatures.size(); i != e; ++i)
1175-
if (MissingFeatures.test(i))
1176-
OS << ' ' << getSubtargetFeatureName(i);
1172+
for (unsigned I = 0, E = MissingFeatures.size(); I != E; ++I)
1173+
if (MissingFeatures.test(I))
1174+
OS << ' ' << getSubtargetFeatureName(I);
11771175
return Parser.Error(IDLoc, Message);
11781176
}
11791177
case Match_MnemonicFail:
@@ -1198,11 +1196,11 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
11981196

11991197
void doBeforeLabelEmit(MCSymbol *Symbol, SMLoc IDLoc) override {
12001198
// Code below only applies to labels in text sections.
1201-
auto CWS = cast<MCSectionWasm>(getStreamer().getCurrentSectionOnly());
1199+
auto *CWS = cast<MCSectionWasm>(getStreamer().getCurrentSectionOnly());
12021200
if (!CWS->isText())
12031201
return;
12041202

1205-
auto WasmSym = cast<MCSymbolWasm>(Symbol);
1203+
auto *WasmSym = cast<MCSymbolWasm>(Symbol);
12061204
// Unlike other targets, we don't allow data in text sections (labels
12071205
// declared with .type @object).
12081206
if (WasmSym->getType() == wasm::WASM_SYMBOL_TYPE_DATA) {
@@ -1222,7 +1220,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
12221220
// its name when we create this one. It would be nice to honor their
12231221
// choice, while still ensuring that we create one if they forget.
12241222
// (that requires coordination with WasmAsmParser::parseSectionDirective)
1225-
auto SecName = ".text." + SymName;
1223+
std::string SecName = (".text." + SymName).str();
12261224

12271225
auto *Group = CWS->getGroup();
12281226
// If the current section is a COMDAT, also set the flag on the symbol.
@@ -1259,7 +1257,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
12591257
if (!SkipTypeCheck)
12601258
TC.endOfFunction(ErrorLoc);
12611259
// Reset the type checker state.
1262-
TC.Clear();
1260+
TC.clear();
12631261
}
12641262

12651263
void onEndOfFile() override { ensureEmptyNestingStack(); }
@@ -1277,7 +1275,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyAsmParser() {
12771275
#define GET_MATCHER_IMPLEMENTATION
12781276
#include "WebAssemblyGenAsmMatcher.inc"
12791277

1280-
StringRef GetMnemonic(unsigned Opc) {
1278+
StringRef getMnemonic(unsigned Opc) {
12811279
// FIXME: linear search!
12821280
for (auto &ME : MatchTable0) {
12831281
if (ME.Opcode == Opc) {

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ using namespace llvm;
3838

3939
#define DEBUG_TYPE "wasm-asm-parser"
4040

41-
extern StringRef GetMnemonic(unsigned Opc);
41+
extern StringRef getMnemonic(unsigned Opc);
4242

4343
namespace llvm {
4444

4545
WebAssemblyAsmTypeCheck::WebAssemblyAsmTypeCheck(MCAsmParser &Parser,
4646
const MCInstrInfo &MII,
47-
bool is64)
48-
: Parser(Parser), MII(MII), is64(is64) {}
47+
bool Is64)
48+
: Parser(Parser), MII(MII), Is64(Is64) {}
4949

5050
void WebAssemblyAsmTypeCheck::funcDecl(const wasm::WasmSignature &Sig) {
5151
LocalTypes.assign(Sig.Params.begin(), Sig.Params.end());
@@ -194,7 +194,7 @@ bool WebAssemblyAsmTypeCheck::getGlobal(SMLoc ErrorLoc,
194194
const MCSymbolRefExpr *SymRef;
195195
if (getSymRef(ErrorLoc, GlobalOp, SymRef))
196196
return true;
197-
auto WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
197+
const auto *WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
198198
switch (WasmSym->getType().value_or(wasm::WASM_SYMBOL_TYPE_DATA)) {
199199
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
200200
Type = static_cast<wasm::ValType>(WasmSym->getGlobalType().Type);
@@ -204,7 +204,7 @@ bool WebAssemblyAsmTypeCheck::getGlobal(SMLoc ErrorLoc,
204204
switch (SymRef->getKind()) {
205205
case MCSymbolRefExpr::VK_GOT:
206206
case MCSymbolRefExpr::VK_WASM_GOT_TLS:
207-
Type = is64 ? wasm::ValType::I64 : wasm::ValType::I32;
207+
Type = Is64 ? wasm::ValType::I64 : wasm::ValType::I32;
208208
return false;
209209
default:
210210
break;
@@ -222,7 +222,7 @@ bool WebAssemblyAsmTypeCheck::getTable(SMLoc ErrorLoc, const MCOperand &TableOp,
222222
const MCSymbolRefExpr *SymRef;
223223
if (getSymRef(ErrorLoc, TableOp, SymRef))
224224
return true;
225-
auto WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
225+
const auto *WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
226226
if (WasmSym->getType().value_or(wasm::WASM_SYMBOL_TYPE_DATA) !=
227227
wasm::WASM_SYMBOL_TYPE_TABLE)
228228
return typeError(ErrorLoc, StringRef("symbol ") + WasmSym->getName() +
@@ -276,7 +276,7 @@ bool WebAssemblyAsmTypeCheck::endOfFunction(SMLoc ErrorLoc) {
276276
bool WebAssemblyAsmTypeCheck::typeCheck(SMLoc ErrorLoc, const MCInst &Inst,
277277
OperandVector &Operands) {
278278
auto Opc = Inst.getOpcode();
279-
auto Name = GetMnemonic(Opc);
279+
auto Name = getMnemonic(Opc);
280280
dumpTypeStack("typechecking " + Name + ": ");
281281
wasm::ValType Type;
282282
if (Name == "local.get") {
@@ -338,23 +338,23 @@ bool WebAssemblyAsmTypeCheck::typeCheck(SMLoc ErrorLoc, const MCInst &Inst,
338338
if (popType(ErrorLoc, wasm::ValType::I32))
339339
return true;
340340
} else if (Name == "memory.fill") {
341-
Type = is64 ? wasm::ValType::I64 : wasm::ValType::I32;
341+
Type = Is64 ? wasm::ValType::I64 : wasm::ValType::I32;
342342
if (popType(ErrorLoc, Type))
343343
return true;
344344
if (popType(ErrorLoc, wasm::ValType::I32))
345345
return true;
346346
if (popType(ErrorLoc, Type))
347347
return true;
348348
} else if (Name == "memory.copy") {
349-
Type = is64 ? wasm::ValType::I64 : wasm::ValType::I32;
349+
Type = Is64 ? wasm::ValType::I64 : wasm::ValType::I32;
350350
if (popType(ErrorLoc, Type))
351351
return true;
352352
if (popType(ErrorLoc, Type))
353353
return true;
354354
if (popType(ErrorLoc, Type))
355355
return true;
356356
} else if (Name == "memory.init") {
357-
Type = is64 ? wasm::ValType::I64 : wasm::ValType::I32;
357+
Type = Is64 ? wasm::ValType::I64 : wasm::ValType::I32;
358358
if (popType(ErrorLoc, wasm::ValType::I32))
359359
return true;
360360
if (popType(ErrorLoc, wasm::ValType::I32))

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class WebAssemblyAsmTypeCheck final {
3535
wasm::WasmSignature LastSig;
3636
bool TypeErrorThisFunction = false;
3737
bool Unreachable = false;
38-
bool is64;
38+
bool Is64;
3939

4040
void dumpTypeStack(Twine Msg);
4141
bool typeError(SMLoc ErrorLoc, const Twine &Msg);
@@ -55,15 +55,15 @@ class WebAssemblyAsmTypeCheck final {
5555

5656
public:
5757
WebAssemblyAsmTypeCheck(MCAsmParser &Parser, const MCInstrInfo &MII,
58-
bool is64);
58+
bool Is64);
5959

6060
void funcDecl(const wasm::WasmSignature &Sig);
6161
void localDecl(const SmallVectorImpl<wasm::ValType> &Locals);
6262
void setLastSig(const wasm::WasmSignature &Sig) { LastSig = Sig; }
6363
bool endOfFunction(SMLoc ErrorLoc);
6464
bool typeCheck(SMLoc ErrorLoc, const MCInst &Inst, OperandVector &Operands);
6565

66-
void Clear() {
66+
void clear() {
6767
Stack.clear();
6868
BrStack.clear();
6969
LocalTypes.clear();

0 commit comments

Comments
 (0)