commit 329457bb4f714a8392153dfecfabd6f356144688 (tree)
parent 7efa2cd81cef69d071982cfaa6953d6b9d4a1c95
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Tue, 14 Mar 2017 21:39:04 -0400
Merge branch 'master' into lld
Diffstat:
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/ir.cpp b/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);
diff --git a/test/cases/cast.zig b/test/cases/cast.zig
@@ -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);
+}