Use unreachable for panic

This commit is contained in:
MrLetsplay 2024-11-16 20:09:29 +01:00
parent 3af1535515
commit 61d8694a02
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
2 changed files with 8 additions and 6 deletions

View File

@ -894,13 +894,10 @@ func (c *Compiler) compileFunctionWAT(function *ParsedFunction) (string, error)
} }
func (c *Compiler) compile() (string, error) { func (c *Compiler) compile() (string, error) {
module := "(module (memory 0)\n" module := "(module (memory $memory 0) (export \"memory\" (memory $memory))\n"
module += "(func $__builtin_panic\n" module += "(func $__builtin_panic\n"
module += "i32.const 0\n" module += "unreachable\n"
module += "i32.const 0\n"
module += "i32.div_u\n"
module += "drop\n"
module += ")\n" module += ")\n"
for _, file := range c.Files { for _, file := range c.Files {

View File

@ -3,7 +3,7 @@ u64 array() {
__builtin_memory_grow(1u64); __builtin_memory_grow(1u64);
} }
raw(u32, 0x0u64) = 1u32; raw(u32, 0x0u64) = 2u32;
raw(u64, 0x04u64) = 69u64; raw(u64, 0x04u64) = 69u64;
u64[] array = raw(u64[], 0x0u64); u64[] array = raw(u64[], 0x0u64);
@ -18,6 +18,11 @@ void array2() {
array[0] = 1u64; array[0] = 1u64;
} }
void outOfBounds() {
u64[] array = raw(u64[], 0x0u64);
array[100] = 69u64;
}
u64[] arrayReturn() { u64[] arrayReturn() {
if(__builtin_memory_size() == 0u64) { if(__builtin_memory_size() == 0u64) {
__builtin_memory_grow(1u64); __builtin_memory_grow(1u64);