Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,13 @@ def get_tests(test_dir, extensions=[], recursive=False):
# delete the old file, make sure you rename the corresponding .wast.log file in
# expected-output/ if any.
SPEC_TESTS_TO_SKIP = [
# Malformed module accepted
# Requires us to write our own floating point parser
'const.wast',
'address.wast',

# Unlinkable module accepted
'linking.wast',

# Invalid module accepted
'func.wast',
'type.wast',
'unreached-invalid.wast',

# Test invalid
Expand Down
5 changes: 5 additions & 0 deletions src/support/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ std::ostream& writeWTF16CodePoint(std::ostream& os, uint32_t u) {
return os;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

bool convertWTF8ToWTF16(std::ostream& os, std::string_view str) {
bool valid = true;
bool lastWasLeadingSurrogate = false;
Expand All @@ -343,6 +346,8 @@ bool convertWTF8ToWTF16(std::ostream& os, std::string_view str) {
return valid;
}

#pragma GCC diagnostic pop

bool convertWTF16ToWTF8(std::ostream& os, std::string_view str) {
return doConvertWTF16ToWTF8(os, str, true);
}
Expand Down
13 changes: 13 additions & 0 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
return info.shouldBeSubType(left, right, curr, text, getFunction());
}

void validateOffset(Address offset, Memory* mem, Expression* curr);
void validateAlignment(
size_t align, Type type, Index bytes, bool isAtomic, Expression* curr);
void validateMemBytes(uint8_t bytes, Type type, Expression* curr);
Expand Down Expand Up @@ -1046,6 +1047,7 @@ void FunctionValidator::visitLoad(Load* curr) {
"SIMD operations require SIMD [--enable-simd]");
}
validateMemBytes(curr->bytes, curr->type, curr);
validateOffset(curr->offset, memory, curr);
validateAlignment(curr->align, curr->type, curr->bytes, curr->isAtomic, curr);
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
Expand Down Expand Up @@ -1077,6 +1079,7 @@ void FunctionValidator::visitStore(Store* curr) {
"SIMD operations require SIMD [--enable-simd]");
}
validateMemBytes(curr->bytes, curr->valueType, curr);
validateOffset(curr->offset, memory, curr);
validateAlignment(
curr->align, curr->valueType, curr->bytes, curr->isAtomic, curr);
shouldBeEqualOrFirstIsUnreachable(
Expand Down Expand Up @@ -1370,6 +1373,7 @@ void FunctionValidator::visitSIMDLoad(SIMDLoad* curr) {
break;
}
Index bytes = curr->getMemBytes();
validateOffset(curr->offset, memory, curr);
validateAlignment(curr->align, memAlignType, bytes, /*isAtomic=*/false, curr);
}

Expand Down Expand Up @@ -1423,6 +1427,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
WASM_UNREACHABLE("Unexpected SIMDLoadStoreLane op");
}
Index bytes = curr->getMemBytes();
validateOffset(curr->offset, memory, curr);
validateAlignment(curr->align, memAlignType, bytes, /*isAtomic=*/false, curr);
shouldBeTrue(curr->index < lanes, curr, "invalid lane index");
}
Expand Down Expand Up @@ -3457,6 +3462,14 @@ void FunctionValidator::visitFunction(Function* curr) {
}
}

void FunctionValidator::validateOffset(Address offset,
Memory* mem,
Expression* curr) {
shouldBeTrue(mem->is64() || offset <= std::numeric_limits<uint32_t>::max(),
curr,
"offset must be u32");
}

void FunctionValidator::validateAlignment(
size_t align, Type type, Index bytes, bool isAtomic, Expression* curr) {
if (isAtomic) {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/address.wast
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
(assert_trap (invoke "16s_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "32_bad" (i32.const 1)) "out of bounds memory access")

(assert_malformed
(assert_invalid
(module quote
"(memory 1)"
"(func (drop (i32.load offset=4294967296 (i32.const 0))))"
Expand Down
13 changes: 0 additions & 13 deletions test/spec/func.wast
Original file line number Diff line number Diff line change
Expand Up @@ -489,19 +489,6 @@

;; Invalid typing of result

(assert_invalid
(module (func $type-multiple-result (result i32 i32) (unreachable)))
"invalid result arity"
)
(assert_invalid
(module
(type (func (result i32 i32)))
(func $type-multiple-result (type 0) (unreachable))
)
"invalid result arity"
)


(assert_invalid
(module (func $type-empty-i32 (result i32)))
"type mismatch"
Expand Down
45 changes: 18 additions & 27 deletions test/spec/type.wast
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@
(type (func (param $x i32) (result i32)))

(type (func (param f32 f64)))
;; (type (func (result i64 f32)))
;; (type (func (param i32 i64) (result f32 f64)))
(type (func (result i64 f32)))
(type (func (param i32 i64) (result f32 f64)))

(type (func (param f32) (param f64)))
(type (func (param $x f32) (param f64)))
(type (func (param f32) (param $y f64)))
(type (func (param $x f32) (param $y f64)))
;; (type (func (result i64) (result f32)))
;; (type (func (param i32) (param i64) (result f32) (result f64)))
;; (type (func (param $x i32) (param $y i64) (result f32) (result f64)))
(type (func (result i64) (result f32)))
(type (func (param i32) (param i64) (result f32) (result f64)))
(type (func (param $x i32) (param $y i64) (result f32) (result f64)))

(type (func (param f32 f64) (param $x i32) (param f64 i32 i32)))
;; (type (func (result i64 i64 f32) (result f32 i32)))
;; (type
;; (func (param i32 i32) (param i64 i32) (result f32 f64) (result f64 i32))
;; )
(type (func (result i64 i64 f32) (result f32 i32)))
(type
(func (param i32 i32) (param i64 i32) (result f32 f64) (result f64 i32))
)

(type (func (param) (param $x f32) (param) (param) (param f64 i32) (param)))
;; (type
;; (func (result) (result) (result i64 i64) (result) (result f32) (result))
;; )
;; (type
;; (func
;; (param i32 i32) (param i64 i32) (param) (param $x i32) (param)
;; (result) (result f32 f64) (result f64 i32) (result)
;; )
;; )
(type
(func (result) (result) (result i64 i64) (result) (result f32) (result))
)
(type
(func
(param i32 i32) (param i64 i32) (param) (param $x i32) (param)
(result) (result f32 f64) (result f64 i32) (result)
)
)
)

(assert_malformed
Expand All @@ -48,12 +48,3 @@
(module quote "(type (func (result $x i32)))")
"unexpected token"
)

(assert_invalid
(module (type (func (result i32 i32))))
"invalid result arity"
)
(assert_invalid
(module (type (func (result i32) (result i32))))
"invalid result arity"
)