[llvm] a872ee2 - [WebAssembly] ensure .functype applies to right label in assembler

Wouter van Oortmerssen via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 5 15:36:37 PST 2021


Author: Wouter van Oortmerssen
Date: 2021-02-05T15:36:15-08:00
New Revision: a872ee2f36d1be16c1b6d4eeac623852434df0bb

URL: https://github.com/llvm/llvm-project/commit/a872ee2f36d1be16c1b6d4eeac623852434df0bb
DIFF: https://github.com/llvm/llvm-project/commit/a872ee2f36d1be16c1b6d4eeac623852434df0bb.diff

LOG: [WebAssembly] ensure .functype applies to right label in assembler

We used to require .functype immediately follows the label it sets the type of, but not all Clang output follows this rule.

Now we simply allow it on any symbol, but only assume its a function start for a defined symbol, which is simpler and more general.

Fixes (part of) https://bugs.llvm.org/show_bug.cgi?id=49036

Differential Revision: https://reviews.llvm.org/D96165

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
    llvm/test/MC/WebAssembly/basic-assembly.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index cf722b0596ee..0328381f9e8a 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -203,7 +203,6 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
   // guarantee that correct order.
   enum ParserState {
     FileStart,
-    Label,
     FunctionStart,
     FunctionLocals,
     Instructions,
@@ -223,9 +222,6 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
   };
   std::vector<NestingType> 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 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
     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 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
       if (SymName.empty())
         return true;
       auto WasmSym = cast<MCSymbolWasm>(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<wasm::WasmSignature>();
@@ -881,7 +872,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
 
     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<wasm::ValType, 4> Locals;
       if (parseRegTypeList(Locals))

diff  --git a/llvm/test/MC/WebAssembly/basic-assembly.s b/llvm/test/MC/WebAssembly/basic-assembly.s
index 786100d91e5c..5da08d6781ab 100644
--- a/llvm/test/MC/WebAssembly/basic-assembly.s
+++ b/llvm/test/MC/WebAssembly/basic-assembly.s
@@ -8,6 +8,8 @@ empty_func:
     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 @@ test0:
     .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 @@ empty_fref_table:
 
 # CHECK:           .tabletype empty_eref_table, externref
 # CHECK-NEXT: empty_eref_table:
-        
+
 # CHECK:           .tabletype empty_fref_table, funcref
 # CHECK-NEXT: empty_fref_table:


        


More information about the llvm-commits mailing list