authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-26 02:53:42-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-26 02:53:42-05:00
log110a6f39ca9cf578e014461f2e9eef2691a2368d
tree3f79a2b00e02f4b7ba876f1b1e9142217a38200b
parent6c9ec3688eead05f1c41e0444a17e1d2bdb7a21e

IR: pass explicitCastMaybePointers test


2 files changed, 12 insertions(+), 5 deletions(-)

src/ir.cpp+4-5
...@@ -5030,11 +5030,10 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -5030,11 +5030,10 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
5030static IrInstruction *ir_analyze_pointer_reinterpret(IrAnalyze *ira, IrInstruction *source_instr,5030static IrInstruction *ir_analyze_pointer_reinterpret(IrAnalyze *ira, IrInstruction *source_instr,
5031 IrInstruction *ptr, TypeTableEntry *wanted_type)5031 IrInstruction *ptr, TypeTableEntry *wanted_type)
5032{5032{
5033 assert(wanted_type->id == TypeTableEntryIdPointer);5033 if (ptr->value.type->id != TypeTableEntryIdPointer &&
50345034 ptr->value.type->id != TypeTableEntryIdMaybe)
5035 if (ptr->value.type->id != TypeTableEntryIdPointer) {5035 {
5036 ir_add_error(ira, ptr,5036 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&ptr->value.type->name)));
5037 buf_sprintf("expected pointer, found '%s'", buf_ptr(&ptr->value.type->name)));
5038 return ira->codegen->invalid_instruction;5037 return ira->codegen->invalid_instruction;
5039 }5038 }
50405039
test/cases/misc.zig+8
...@@ -271,6 +271,14 @@ fn compileTimeGlobalReinterpret() {...@@ -271,6 +271,14 @@ fn compileTimeGlobalReinterpret() {
271 assert(*d == 1234);271 assert(*d == 1234);
272}272}
273273
274fn explicitCastMaybePointers() {
275 @setFnTest(this);
276
277 const a: ?&i32 = undefined;
278 const b: ?&f32 = (?&f32)(a);
279}
280
281
274// TODO import from std.str282// TODO import from std.str
275pub fn memeql(a: []const u8, b: []const u8) -> bool {283pub fn memeql(a: []const u8, b: []const u8) -> bool {
276 sliceEql(u8, a, b)284 sliceEql(u8, a, b)