Skip to content

Commit 4e3fe04

Browse files
committed
[WATParser] Skip identifiers in ParseDeclsCtx::skipFunctionBody
Without taking identifiers in ParseDeclsCtx::skipFunctionBody, an identifier starting with a block or indirect call keyword (such as $block or $call_indirect) would have only its leading '$' consumed by in.take(1) and then be misparsed as a keyword on the next iteration, adding a spurious implicit function type.
1 parent 131ccdf commit 4e3fe04

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎src/parser/context-decls.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ bool ParseDeclsCtx::skipFunctionBody() {
321321
--depth;
322322
continue;
323323
}
324+
if (in.takeID()) {
325+
continue;
326+
}
324327
if (auto kw = in.takeKeyword()) {
325328
if (*kw == "block"sv || *kw == "loop"sv || *kw == "if"sv ||
326329
*kw == "try"sv || *kw == "try_table"sv) {

‎test/lit/blocktype.wast‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,34 @@
3737
)
3838

3939
;; CHECK: (func $f2 (type $f2) (result (ref $f2) (ref $f1))
40-
;; CHECK-NEXT: (loop $l (type $f2) (result (ref $f2) (ref $f1))
41-
;; CHECK-NEXT: (call $f2)
40+
;; CHECK-NEXT: (loop $block (type $f2) (result (ref $f2) (ref $f1))
41+
;; CHECK-NEXT: (br $block)
4242
;; CHECK-NEXT: )
4343
;; CHECK-NEXT: )
4444
;; RTRIP: (func $f2 (type $f2) (result (ref $f2) (ref $f1))
45-
;; RTRIP-NEXT: (loop (type $f2) (result (ref $f2) (ref $f1))
46-
;; RTRIP-NEXT: (call $f2)
45+
;; RTRIP-NEXT: (loop $label (type $f2) (result (ref $f2) (ref $f1))
46+
;; RTRIP-NEXT: (br $label)
4747
;; RTRIP-NEXT: )
4848
;; RTRIP-NEXT: )
4949
(func $f2 (type $f2) (result (ref $f2) (ref $f1))
5050
;; This block will be emitted with type $f2
51-
(loop $l (type $block2) (result (ref $f2) (ref $f1))
52-
(call $f2)
51+
(loop $block (type $block2) (result (ref $f2) (ref $f1))
52+
(br $block)
53+
)
54+
)
55+
56+
;; CHECK: (func $f3 (type $2) (result i32)
57+
;; CHECK-NEXT: (i32.const 0)
58+
;; CHECK-NEXT: )
59+
;; RTRIP: (func $f3 (type $2) (result i32)
60+
;; RTRIP-NEXT: (i32.const 0)
61+
;; RTRIP-NEXT: )
62+
(func $f3 (result i32)
63+
;; Type index 4 is the implicit (func (result i32)) from $f3's signature,
64+
;; unless $block in $f2 was parsed as a block keyword and created a
65+
;; spurious () -> () implicit type at index 4.
66+
(block (type 4) (result i32)
67+
(i32.const 0)
5368
)
5469
)
5570
)

0 commit comments

Comments
 (0)