Skip to content

Commit 6b596f1

Browse files
authored
Remove a special cased error message in roundtrip tests (#1550)
Use the features on `BinaryReader` to dictate what the valid flags are for a global.
1 parent 777f8be commit 6b596f1

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

crates/wasmparser/src/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ impl Parser {
715715
self.max_size -= u64::from(len);
716716
self.offset += u64::from(len);
717717
let mut parser = Parser::new(usize_to_u64(reader.original_position()));
718+
parser.features = self.features;
718719
parser.max_size = u64::from(len);
719720

720721
Ok(match id {

crates/wasmparser/src/readers/core/globals.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@ impl<'a> FromReader<'a> for GlobalType {
3939
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
4040
let content_type = reader.read()?;
4141
let flags = reader.read_u8()?;
42-
if flags > 0b11 {
43-
bail!(reader.original_position() - 1, "malformed global flags")
42+
if reader.features().shared_everything_threads() {
43+
if flags > 0b11 {
44+
bail!(reader.original_position() - 1, "malformed global flags")
45+
}
46+
} else {
47+
if flags > 0b1 {
48+
bail!(
49+
reader.original_position() - 1,
50+
"malformed mutability -- or shared globals \
51+
require the shared-everything-threads proposal"
52+
)
53+
}
4454
}
4555
Ok(GlobalType {
4656
content_type,

crates/wasmparser/src/validator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ impl Validator {
455455
pub fn validate_all(&mut self, bytes: &[u8]) -> Result<Types> {
456456
let mut functions_to_validate = Vec::new();
457457
let mut last_types = None;
458-
for payload in Parser::new(0).parse_all(bytes) {
458+
let mut parser = Parser::new(0);
459+
parser.set_features(self.features);
460+
for payload in parser.parse_all(bytes) {
459461
match self.payload(&payload?)? {
460462
ValidPayload::Func(a, b) => {
461463
functions_to_validate.push((a, b));

tests/roundtrip.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -818,16 +818,6 @@ fn error_matches(error: &str, message: &str) -> bool {
818818
return error.starts_with("type mismatch");
819819
}
820820

821-
if message == "malformed mutability" {
822-
// When parsing a global `shared` type (e.g., `global (mut shared i32)
823-
// ...`), many spec tests expect a `malformed mutability` error.
824-
// Previously, `0x2` was an invalid flag but it now means `shared`. We
825-
// accept either (a) a new, more accurate error message or (b) a
826-
// validation error instead.
827-
return error.contains("malformed global flags")
828-
|| error.contains("require the shared-everything-threads proposal");
829-
}
830-
831821
if message == "table size must be at most 2^32-1" {
832822
return error.contains("invalid u32 number: constant out of range");
833823
}

0 commit comments

Comments
 (0)