Skip to content

Commit f2e7033

Browse files
WAT: Ban non-power-of-2 alignment values
1 parent 7bcf810 commit f2e7033

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Sources/WAT/Parser/ExpressionParser.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ struct ExpressionParser<Visitor: InstructionVisitor> {
398398
try parser.consume()
399399
var subParser = Parser(String(maybeAlign.dropFirst(alignPrefix.count)))
400400
align = try subParser.expectUnsignedInt(UInt32.self)
401+
402+
if align == 0 || align & (align - 1) != 0 {
403+
throw WatParserError("alignment must be a power of 2", location: subParser.lexer.location())
404+
}
401405
}
402406
return MemArg(offset: offset, align: align)
403407
}

Tests/WATTests/EncoderTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ class EncoderTests: XCTestCase {
107107

108108
var stats = CompatibilityTestStats()
109109
let excluded: [String] = [
110-
"align.wast",
111-
"align64.wast",
112110
"block.wast",
113111
"call_indirect.wast",
114112
"const.wast",

0 commit comments

Comments
 (0)