From 19ddbd9e9e691ff7ab8789e8c6962497fbba4b88 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 15 Dec 2019 12:48:35 +0100 Subject: Make sure the address is aligned for intToPtr ops Closes #773 --- src/ir.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index da208b62c6..8e1cef8e43 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -26606,6 +26606,14 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc return ira->codegen->invalid_instruction; } + const uint32_t align_bytes = get_ptr_align(ira->codegen, ptr_type); + if (addr != 0 && addr % align_bytes != 0) { + ir_add_error(ira, source_instr, + buf_sprintf("pointer type '%s' requires aligned address", + buf_ptr(&ptr_type->name))); + return ira->codegen->invalid_instruction; + } + IrInstruction *result = ir_const(ira, source_instr, ptr_type); result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; -- cgit v1.2.3