From 118cf95d2520ccef3797e18d4836ab7942f1d7d3 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Sat, 10 Feb 2018 12:20:19 +0100 Subject: [PATCH] Even more testing for #26 --- tests/compiler/overflow.optimized.wast | 95 +++++++++++++++- tests/compiler/overflow.ts | 15 +++ tests/compiler/overflow.wast | 151 ++++++++++++++++++++++++- 3 files changed, 259 insertions(+), 2 deletions(-) diff --git a/tests/compiler/overflow.optimized.wast b/tests/compiler/overflow.optimized.wast index 423898fb..204953f3 100644 --- a/tests/compiler/overflow.optimized.wast +++ b/tests/compiler/overflow.optimized.wast @@ -2,6 +2,7 @@ (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) (type $i (func (result i32))) + (type $iv (func (param i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $overflow/badByte (mut i32) (i32.const 255)) (global $overflow/anotherBadByte (mut i32) (i32.const 255)) @@ -23,7 +24,27 @@ (i32.const 0) ) ) - (func $start (; 3 ;) (type $v) + (func $overflow/storeU8FFadd1 (; 3 ;) (type $iv) (param $0 i32) + (i32.store8 + (i32.const 0) + (get_local $0) + ) + (if + (i32.load8_u + (i32.const 0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 36) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (func $start (; 4 ;) (type $v) (set_global $overflow/badByte (i32.and (i32.add @@ -91,5 +112,77 @@ (unreachable) ) ) + (set_global $overflow/valueU8 + (i32.const 255) + ) + (call $overflow/storeU8FFadd1 + (i32.and + (i32.add + (get_global $overflow/valueU8) + (i32.const 1) + ) + (i32.const 255) + ) + ) + (i32.store8 + (i32.const 0) + (i32.add + (get_global $overflow/valueU8) + (i32.const 1) + ) + ) + (if + (i32.load8_u + (i32.const 0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 43) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $overflow/valueU8 + (i32.and + (i32.add + (get_global $overflow/valueU8) + (i32.const 1) + ) + (i32.const 255) + ) + ) + (i32.store8 + (i32.const 0) + (get_global $overflow/valueU8) + ) + (if + (i32.load8_u + (i32.const 0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 46) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (get_global $overflow/valueU8) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 47) + (i32.const 0) + ) + (unreachable) + ) + ) ) ) diff --git a/tests/compiler/overflow.ts b/tests/compiler/overflow.ts index e4c45187..dd305a77 100644 --- a/tests/compiler/overflow.ts +++ b/tests/compiler/overflow.ts @@ -30,3 +30,18 @@ function loadU8FF(): u8 { var valueU8: u8 = loadU8FF(); valueU8 += 1; assert(valueU8 == 0); + +function storeU8FFadd1(val: u8): void { + store(0, val); + assert(load(0) == 0); +} + +valueU8 = 0xFF; +storeU8FFadd1(valueU8 + 1); + +store(0, valueU8 + 1); +assert(load(0) == 0); + +store(0, ++valueU8); +assert(load(0) == 0); +assert(valueU8 == 0); diff --git a/tests/compiler/overflow.wast b/tests/compiler/overflow.wast index 570f2580..8b16c162 100644 --- a/tests/compiler/overflow.wast +++ b/tests/compiler/overflow.wast @@ -2,6 +2,7 @@ (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) (type $i (func (result i32))) + (type $iv (func (param i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $overflow/badByte (mut i32) (i32.const 255)) (global $overflow/anotherBadByte (mut i32) (i32.const 255)) @@ -111,7 +112,39 @@ ) ) ) - (func $start (; 3 ;) (type $v) + (func $overflow/storeU8FFadd1 (; 3 ;) (type $iv) (param $0 i32) + ;;@ overflow.ts:35:2 + (i32.store8 + ;;@ overflow.ts:35:12 + (i32.const 0) + ;;@ overflow.ts:35:15 + (get_local $0) + ) + ;;@ overflow.ts:36:2 + (if + (i32.eqz + ;;@ overflow.ts:36:9 + (i32.eq + (i32.load8_u + ;;@ overflow.ts:36:18 + (i32.const 0) + ) + ;;@ overflow.ts:36:24 + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 36) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (func $start (; 4 ;) (type $v) ;;@ overflow.ts:4:0 (set_global $overflow/badByte (i32.and @@ -211,5 +244,121 @@ (unreachable) ) ) + ;;@ overflow.ts:39:0 + (set_global $overflow/valueU8 + ;;@ overflow.ts:39:10 + (i32.const 255) + ) + ;;@ overflow.ts:40:0 + (call $overflow/storeU8FFadd1 + ;;@ overflow.ts:40:14 + (i32.and + (i32.add + (get_global $overflow/valueU8) + ;;@ overflow.ts:40:24 + (i32.const 1) + ) + (i32.const 255) + ) + ) + ;;@ overflow.ts:42:0 + (i32.store8 + ;;@ overflow.ts:42:10 + (i32.const 0) + ;;@ overflow.ts:42:13 + (i32.and + (i32.add + (get_global $overflow/valueU8) + ;;@ overflow.ts:42:23 + (i32.const 1) + ) + (i32.const 255) + ) + ) + ;;@ overflow.ts:43:0 + (if + (i32.eqz + ;;@ overflow.ts:43:7 + (i32.eq + (i32.load8_u + ;;@ overflow.ts:43:16 + (i32.const 0) + ) + ;;@ overflow.ts:43:22 + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 43) + (i32.const 0) + ) + (unreachable) + ) + ) + ;;@ overflow.ts:45:0 + (i32.store8 + ;;@ overflow.ts:45:10 + (i32.const 0) + ;;@ overflow.ts:45:13 + (block (result i32) + (set_global $overflow/valueU8 + (i32.and + (i32.add + ;;@ overflow.ts:45:15 + (get_global $overflow/valueU8) + (i32.const 1) + ) + (i32.const 255) + ) + ) + (get_global $overflow/valueU8) + ) + ) + ;;@ overflow.ts:46:0 + (if + (i32.eqz + ;;@ overflow.ts:46:7 + (i32.eq + (i32.load8_u + ;;@ overflow.ts:46:16 + (i32.const 0) + ) + ;;@ overflow.ts:46:22 + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 46) + (i32.const 0) + ) + (unreachable) + ) + ) + ;;@ overflow.ts:47:0 + (if + (i32.eqz + ;;@ overflow.ts:47:7 + (i32.eq + (get_global $overflow/valueU8) + ;;@ overflow.ts:47:18 + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 8) + (i32.const 47) + (i32.const 0) + ) + (unreachable) + ) + ) ) )