diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 237f59a9b6d..005db54be5d 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -421,7 +421,6 @@ def get_tests(test_dir, extensions=[], recursive=False): 'const.wast', # Hex float constant not recognized as out of range 'conversions.wast', # Promoted NaN should be canonical 'data.wast', # Constant global references allowed by GC - 'elem.wast', # Requires modeling empty declarative segments 'f32.wast', # Adding -0 and -nan should give a canonical NaN 'f64.wast', # Adding -0 and -nan should give a canonical NaN 'float_exprs.wast', # Adding 0 and NaN should give canonical NaN diff --git a/src/parser/context-decls.cpp b/src/parser/context-decls.cpp index c124689d334..cd1c0e13c25 100644 --- a/src/parser/context-decls.cpp +++ b/src/parser/context-decls.cpp @@ -241,6 +241,19 @@ Result<> ParseDeclsCtx::addElem( return Ok{}; } +Result<> ParseDeclsCtx::addDeclareElem(Name name, ElemListT&&, Index) { + auto e = std::make_unique(); + if (name) { + e->setExplicitName(name); + } else { + name = std::to_string(elemCounter++); + name = Names::getValidElementSegmentName(wasm, name); + e->name = name; + } + wasm.addElementSegment(std::move(e)); + return Ok{}; +} + Result<> ParseDeclsCtx::addData(Name name, MemoryIdxT*, std::optional, diff --git a/src/parser/contexts.h b/src/parser/contexts.h index 48234829b5a..ef9ea48958f 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -1116,7 +1116,7 @@ struct ParseDeclsCtx : NullTypeParserCtx, NullInstrParserCtx { Result<> addElem(Name, TableIdxT*, std::optional, ElemListT&&, Index); - Result<> addDeclareElem(Name, ElemListT&&, Index) { return Ok{}; } + Result<> addDeclareElem(Name, ElemListT&&, Index); Result<> addData(Name name, MemoryIdxT*, diff --git a/test/lit/basic/multi-table.wast b/test/lit/basic/multi-table.wast index 2d6b436a62d..2b9114b03ce 100644 --- a/test/lit/basic/multi-table.wast +++ b/test/lit/basic/multi-table.wast @@ -76,6 +76,8 @@ ;; CHECK-TEXT: (elem $empty func) ;; CHECK-BIN: (elem $empty func) (elem $empty func) + ;; CHECK-TEXT: (elem $declarative func) + ;; CHECK-BIN: (elem $declarative func) (elem $declarative declare func $h) ;; This elem will be emitted as usesExpressions because of the type of the @@ -142,7 +144,9 @@ ;; CHECK-BIN-NODEBUG: (elem $8 func) -;; CHECK-BIN-NODEBUG: (elem $9 (table $3) (i32.const 0) (ref null $0) (item (ref.func $0)) (item (ref.func $2))) +;; CHECK-BIN-NODEBUG: (elem $9 func) + +;; CHECK-BIN-NODEBUG: (elem $10 (table $3) (i32.const 0) (ref null $0) (item (ref.func $0)) (item (ref.func $2))) ;; CHECK-BIN-NODEBUG: (func $0 (type $0) ;; CHECK-BIN-NODEBUG-NEXT: (drop