| ... | ... | @@ -166,6 +166,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node, |
| 166 | 166 | static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, |
| 167 | 167 | ZigType *dest_type, IrInstruction *dest_type_src); |
| 168 | 168 | static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); |
| 169 | static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs); |
| 169 | 170 | |
| 170 | 171 | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { |
| 171 | 172 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| ... | ... | @@ -7364,15 +7365,31 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, |
| 7364 | 7365 | return ir_add_error_node(ira, source_instruction->source_node, msg); |
| 7365 | 7366 | } |
| 7366 | 7367 | |
| 7368 | // This function takes a comptime ptr and makes the child const value conform to the type |
| 7369 | // described by the pointer. |
| 7370 | static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, AstNode *source_node, ConstExprValue *ptr_val) { |
| 7371 | Error err; |
| 7372 | assert(ptr_val->type->id == ZigTypeIdPointer); |
| 7373 | ConstExprValue tmp = {}; |
| 7374 | tmp.special = ConstValSpecialStatic; |
| 7375 | tmp.type = ptr_val->type->data.pointer.child_type; |
| 7376 | if ((err = ir_read_const_ptr(ira, source_node, &tmp, ptr_val))) |
| 7377 | return err; |
| 7378 | ConstExprValue *child_val = const_ptr_pointee_unchecked(ira->codegen, ptr_val); |
| 7379 | copy_const_val(child_val, &tmp, false); |
| 7380 | return ErrorNone; |
| 7381 | } |
| 7382 | |
| 7367 | 7383 | static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) { |
| 7384 | Error err; |
| 7368 | 7385 | ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val); |
| 7369 | 7386 | assert(val != nullptr); |
| 7370 | 7387 | assert(const_val->type->id == ZigTypeIdPointer); |
| 7371 | 7388 | ZigType *expected_type = const_val->type->data.pointer.child_type; |
| 7372 | 7389 | if (!types_have_same_zig_comptime_repr(val->type, expected_type)) { |
| 7373 | | ir_add_error_node(ira, source_node, |
| 7374 | | buf_sprintf("TODO handle comptime reinterpreted pointer. See https://github.com/ziglang/zig/issues/955")); |
| 7375 | | return nullptr; |
| 7390 | if ((err = eval_comptime_ptr_reinterpret(ira, source_node, const_val))) |
| 7391 | return nullptr; |
| 7392 | return const_ptr_pointee_unchecked(ira->codegen, const_val); |
| 7376 | 7393 | } |
| 7377 | 7394 | return val; |
| 7378 | 7395 | } |
| ... | ... | @@ -19990,6 +20007,8 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct |
| 19990 | 20007 | } |
| 19991 | 20008 | |
| 19992 | 20009 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { |
| 20010 | if (val->special == ConstValSpecialUndef) |
| 20011 | val->special = ConstValSpecialStatic; |
| 19993 | 20012 | assert(val->special == ConstValSpecialStatic); |
| 19994 | 20013 | switch (val->type->id) { |
| 19995 | 20014 | case ZigTypeIdInvalid: |