From ab0cee3dfbc5bed044211e248b55b48292786cde Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Tue, 30 Jul 2024 22:46:45 +0800 Subject: [PATCH] Fix misaligned stack access in the interpreter --- src/compiler/crystal/interpreter/interpreter.cr | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/crystal/interpreter/interpreter.cr b/src/compiler/crystal/interpreter/interpreter.cr index eca73ecae6bc..aa90d83f413f 100644 --- a/src/compiler/crystal/interpreter/interpreter.cr +++ b/src/compiler/crystal/interpreter/interpreter.cr @@ -999,14 +999,15 @@ class Crystal::Repl::Interpreter private macro stack_pop(t) %aligned_size = align(sizeof({{t}})) - %value = (stack - %aligned_size).as({{t}}*).value + %value = uninitialized {{t}} + (stack - %aligned_size).copy_to(pointerof(%value).as(UInt8*), sizeof({{t}})) stack_shrink_by(%aligned_size) %value end private macro stack_push(value) %temp = {{value}} - stack.as(Pointer(typeof({{value}}))).value = %temp + stack.copy_from(pointerof(%temp).as(UInt8*), sizeof(typeof({{value}}))) %size = sizeof(typeof({{value}})) %aligned_size = align(%size)