diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -203,7 +203,6 @@ // guarantee that correct order. enum ParserState { FileStart, - Label, FunctionStart, FunctionLocals, Instructions, @@ -223,9 +222,6 @@ }; std::vector NestingStack; - // We track this to see if a .functype following a label is the same, - // as this is how we recognize the start of a function. - MCSymbol *LastLabel = nullptr; MCSymbol *LastFunctionLabel = nullptr; public: @@ -687,11 +683,6 @@ return false; } - void onLabelParsed(MCSymbol *Symbol) override { - LastLabel = Symbol; - CurrentState = Label; - } - bool parseSignature(wasm::WasmSignature *Signature) { if (expect(AsmToken::LParen, "(")) return true; @@ -808,12 +799,12 @@ if (SymName.empty()) return true; auto WasmSym = cast(Ctx.getOrCreateSymbol(SymName)); - if (CurrentState == Label && WasmSym == LastLabel) { + if (WasmSym->isDefined()) { // This .functype indicates a start of a function. if (ensureEmptyNestingStack()) return true; CurrentState = FunctionStart; - LastFunctionLabel = LastLabel; + LastFunctionLabel = WasmSym; push(Function); } auto Signature = std::make_unique(); @@ -881,7 +872,7 @@ if (DirectiveID.getString() == ".local") { if (CurrentState != FunctionStart) - return error(".local directive should follow the start of a function", + return error(".local directive should follow the start of a function: ", Lexer.getTok()); SmallVector Locals; if (parseRegTypeList(Locals)) diff --git a/llvm/test/MC/WebAssembly/basic-assembly.s b/llvm/test/MC/WebAssembly/basic-assembly.s --- a/llvm/test/MC/WebAssembly/basic-assembly.s +++ b/llvm/test/MC/WebAssembly/basic-assembly.s @@ -8,6 +8,8 @@ end_function test0: +# local labels can appear between label and its .functype. +.Ltest0begin: # Test all types: .functype test0 (i32, i64) -> (i32) .eventtype __cpp_exception i32 @@ -116,17 +118,18 @@ .globaltype __stack_pointer, i32 .tabletype empty_eref_table, externref -empty_eref_table: +empty_eref_table: .tabletype empty_fref_table, funcref -empty_fref_table: +empty_fref_table: + - # CHECK: .text # CHECK-LABEL: empty_func: # CHECK-NEXT: .functype empty_func () -> () # CHECK-NEXT: end_function # CHECK-LABEL: test0: +# CHECK-NEXT: .Ltest0begin: # CHECK-NEXT: .functype test0 (i32, i64) -> (i32) # CHECK-NEXT: .eventtype __cpp_exception i32 # CHECK-NEXT: .local f32, f64 @@ -226,6 +229,6 @@ # CHECK: .tabletype empty_eref_table, externref # CHECK-NEXT: empty_eref_table: - + # CHECK: .tabletype empty_fref_table, funcref # CHECK-NEXT: empty_fref_table: