authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-14 21:39:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-14 21:39:04-04:00
log329457bb4f714a8392153dfecfabd6f356144688
treed55866d855defafea10490fa2e7ce8db69535255
parent7efa2cd81cef69d071982cfaa6953d6b9d4a1c95
parenta76558db26ea175504830ae4aa840a1aa82b16d0

Merge branch 'master' into lld


2 files changed, 16 insertions(+), 4 deletions(-)

src/ir.cpp+6-4
......@@ -8538,11 +8538,13 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
85388538 // this dereference is always an rvalue because in the IR gen we identify lvalue and emit
85398539 // one of the ptr instructions
85408540
8541 if (value->value.special != ConstValSpecialRuntime) {
8542 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
8541 if (instr_is_comptime(value)) {
85438542 ConstExprValue *pointee = const_ptr_pointee(&value->value);
8544 *out_val = *pointee;
8545 return child_type;
8543 if (pointee->type == child_type) {
8544 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
8545 *out_val = *pointee;
8546 return child_type;
8547 }
85468548 }
85478549
85488550 ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value);
test/cases/cast.zig+10
......@@ -15,3 +15,13 @@ fn numLitIntToPtrCast() {
1515 const vga_mem = (&u16)(0xB8000);
1616 assert(usize(vga_mem) == 0xB8000);
1717}
18
19fn pointerReinterpretConstFloatToInt() {
20 @setFnTest(this);
21
22 const float: f64 = 5.99999999999994648725e-01;
23 const float_ptr = &float;
24 const int_ptr = (&i32)(float_ptr);
25 const int_val = *int_ptr;
26 assert(int_val == 858993411);
27}