Skip to content

Commit 38e0f4e

Browse files
authored
Only add exact casts when allowed in GUFA (#7518)
When custom descriptors are disabled, make sure the types of added casts are inexact because exact casts would be invalid.
1 parent 355fae6 commit 38e0f4e

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
'coalesce-locals-exact.wast',
123123
'remove-unused-brs-exact.wast',
124124
'signature-refining-exact.wast',
125+
'gufa-cast-all-exact.wast',
125126
# TODO: fuzzer support for custom descriptors
126127
'custom-descriptors.wast',
127128
]

src/passes/GUFA.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ struct GUFAOptimizer
374374
}
375375

376376
auto oracleType = parent.getContents(curr).getType();
377+
// Exact casts are only allowed when custom descriptors is enabled.
378+
if (oracleType.isExact() &&
379+
!getModule()->features.hasCustomDescriptors()) {
380+
oracleType = oracleType.with(Inexact);
381+
}
377382
if (oracleType.isRef() && oracleType != curr->type &&
378383
Type::isSubType(oracleType, curr->type)) {
379384
replaceCurrent(Builder(*getModule()).makeRefCast(curr, oracleType));
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
3+
;; Check that exact casts are only added when custom descriptors are enabled.
4+
5+
;; RUN: wasm-opt %s -all --gufa-cast-all -S -o - | filecheck %s
6+
;; RUN: wasm-opt %s -all --disable-custom-descriptors --gufa-cast-all -S -o - | filecheck %s --check-prefix=NO_CD
7+
8+
(module
9+
;; CHECK: (type $foo (struct))
10+
;; NO_CD: (type $foo (struct))
11+
(type $foo (struct))
12+
13+
;; CHECK: (import "" "" (global $g (ref (exact $foo))))
14+
;; NO_CD: (import "" "" (global $g (ref (exact $foo))))
15+
(import "" "" (global $g (ref (exact $foo))))
16+
17+
;; CHECK: (func $callee (type $1) (result (ref $foo))
18+
;; CHECK-NEXT: (global.get $g)
19+
;; CHECK-NEXT: )
20+
;; NO_CD: (func $callee (type $1) (result (ref $foo))
21+
;; NO_CD-NEXT: (global.get $g)
22+
;; NO_CD-NEXT: )
23+
(func $callee (result (ref $foo))
24+
(global.get $g)
25+
)
26+
27+
;; CHECK: (func $caller (type $2)
28+
;; CHECK-NEXT: (drop
29+
;; CHECK-NEXT: (block (result (ref (exact $foo)))
30+
;; CHECK-NEXT: (drop
31+
;; CHECK-NEXT: (ref.cast (ref (exact $foo))
32+
;; CHECK-NEXT: (call $callee)
33+
;; CHECK-NEXT: )
34+
;; CHECK-NEXT: )
35+
;; CHECK-NEXT: (global.get $g)
36+
;; CHECK-NEXT: )
37+
;; CHECK-NEXT: )
38+
;; CHECK-NEXT: )
39+
;; NO_CD: (func $caller (type $2)
40+
;; NO_CD-NEXT: (drop
41+
;; NO_CD-NEXT: (block (result (ref (exact $foo)))
42+
;; NO_CD-NEXT: (drop
43+
;; NO_CD-NEXT: (call $callee)
44+
;; NO_CD-NEXT: )
45+
;; NO_CD-NEXT: (global.get $g)
46+
;; NO_CD-NEXT: )
47+
;; NO_CD-NEXT: )
48+
;; NO_CD-NEXT: )
49+
(func $caller
50+
(drop
51+
(call $callee)
52+
)
53+
)
54+
)

0 commit comments

Comments
 (0)