diff options
| author | LemonBoy <thatlemon@gmail.com> | 2019-12-15 12:48:35 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-12-15 14:41:05 -0500 |
| commit | 19ddbd9e9e691ff7ab8789e8c6962497fbba4b88 (patch) | |
| tree | f7523737827e07e2b17f7d6ce2a64d630b814f4c /src/ir.cpp | |
| parent | cf0d300ddecf3e1bf0363002c995425dab007b74 (diff) | |
| download | zig-19ddbd9e9e691ff7ab8789e8c6962497fbba4b88.tar.gz zig-19ddbd9e9e691ff7ab8789e8c6962497fbba4b88.zip | |
Make sure the address is aligned for intToPtr ops
Closes #773
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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; |
