langref: docs for invalid error set cast and incorrect pointer alignment

also add detection of incorrect pointer alignment at compile-time
of pointers that were constructed with `@intToPtr`.
This commit is contained in:
Andrew Kelley
2018-07-09 11:13:29 -04:00
parent 9eb51e20ed
commit 2ee67b7642
3 changed files with 70 additions and 3 deletions

View File

@@ -19370,6 +19370,15 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
if (!val)
return ira->codegen->invalid_instruction;
if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
{
ir_add_error(ira, target,
buf_sprintf("pointer address 0x%lx is not aligned to %" PRIu32 " bytes",
val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
return ira->codegen->invalid_instruction;
}
IrInstruction *result = ir_create_const(&ira->new_irb, target->scope, target->source_node, result_type);
copy_const_val(&result->value, val, false);
result->value.type = result_type;