fix behavior with reinterpreting constant memory

This commit is contained in:
Andrew Kelley 2017-03-14 21:38:27 -04:00
parent 7bc0145b80
commit a76558db26
2 changed files with 16 additions and 4 deletions

View File

@ -8538,11 +8538,13 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
// this dereference is always an rvalue because in the IR gen we identify lvalue and emit
// one of the ptr instructions
if (value->value.special != ConstValSpecialRuntime) {
ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
if (instr_is_comptime(value)) {
ConstExprValue *pointee = const_ptr_pointee(&value->value);
*out_val = *pointee;
return child_type;
if (pointee->type == child_type) {
ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
*out_val = *pointee;
return child_type;
}
}
ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value);

View File

@ -15,3 +15,13 @@ fn numLitIntToPtrCast() {
const vga_mem = (&u16)(0xB8000);
assert(usize(vga_mem) == 0xB8000);
}
fn pointerReinterpretConstFloatToInt() {
@setFnTest(this);
const float: f64 = 5.99999999999994648725e-01;
const float_ptr = &float;
const int_ptr = (&i32)(float_ptr);
const int_val = *int_ptr;
assert(int_val == 858993411);
}