fix behavior with reinterpreting constant memory
This commit is contained in:
parent
7bc0145b80
commit
a76558db26
10
src/ir.cpp
10
src/ir.cpp
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user