forked from WebAssembly/binaryen
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MemoryPacking: Handle non-empty trapping segments (WebAssembly#6261)
Followup to WebAssembly#6243 which handled empty ones.
- Loading branch information
1 parent
ead8381
commit b78f620
Showing
2 changed files
with
153 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
|
||
;; RUN: foreach %s %t wasm-opt --memory-packing -all --zero-filled-memory -S -o - | filecheck %s | ||
;; RUN: foreach %s %t wasm-opt --memory-packing -all --zero-filled-memory -tnh -S -o - | filecheck %s --check-prefix=TNH__ | ||
|
||
(module | ||
;; We should not optimize out a segment that will trap, as that is an effect | ||
;; we need to preserve (unless TrapsNeverHappen). | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
;; CHECK: (data $data (i32.const -1) "\00") | ||
(data $data (i32.const -1) "\00") | ||
) | ||
|
||
(module | ||
;; We should handle the possible overflow in adding the offset and size, and | ||
;; see this might trap. To keep the segment trapping, we will emit a segment | ||
;; with offset -1 of size 1 (which is the minimal thing we need for a trap). | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
;; CHECK: (data $data (i32.const -1) "\00") | ||
(data $data (i32.const -2) "\00\00\00") | ||
) | ||
|
||
(module | ||
;; This segment will almost trap, but not. | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
(data $data (i32.const 65535) "\00") | ||
) | ||
|
||
(module | ||
;; This one is slightly larger, and will trap. We can at least shorten the | ||
;; segment to only contain one byte, at the highest address the segment would | ||
;; write to. | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
;; CHECK: (data $data (i32.const 65536) "\00") | ||
(data $data (i32.const 65535) "\00\00") | ||
) | ||
|
||
(module | ||
;; This one is slightly larger, but the offset is lower so it will not trap. | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
(data $data (i32.const 65534) "\00\00") | ||
) | ||
|
||
(module | ||
;; This one's offset is just large enough to trap. | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
;; CHECK: (data $data (i32.const 65536) "\00") | ||
(data $data (i32.const 65536) "\00") | ||
) | ||
|
||
(module | ||
;; This offset is unknown, so assume the worst. | ||
;; TODO: We could remove it in TNH mode | ||
|
||
;; CHECK: (import "a" "b" (global $g i32)) | ||
;; TNH__: (import "a" "b" (global $g i32)) | ||
(import "a" "b" (global $g i32)) | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
;; CHECK: (data $data (global.get $g) "\00") | ||
;; TNH__: (data $data (global.get $g) "\00") | ||
(data $data (global.get $g) "\00") | ||
) | ||
|
||
(module | ||
;; Passive segments cannot trap during startup and are removable if they have | ||
;; no uses, like here. | ||
;; CHECK: (memory $memory 1 2) | ||
;; TNH__: (memory $memory 1 2) | ||
(memory $memory 1 2) | ||
(data $data "\00\00\00") | ||
) |