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
50305030static IrInstruction *ir_analyze_pointer_reinterpret(IrAnalyze *ira, IrInstruction *source_instr,
50315031 IrInstruction *ptr, TypeTableEntry *wanted_type)
50325032{
5033 assert(wanted_type->id == TypeTableEntryIdPointer);
5034
5035 if (ptr->value.type->id != TypeTableEntryIdPointer) {
5036 ir_add_error(ira, ptr,
5037 buf_sprintf("expected pointer, found '%s'", buf_ptr(&ptr->value.type->name)));
5033 if (ptr->value.type->id != TypeTableEntryIdPointer &&
5034 ptr->value.type->id != TypeTableEntryIdMaybe)
5035 {
5036 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&ptr->value.type->name)));
50385037 return ira->codegen->invalid_instruction;
50395038 }
50405039
test/cases/misc.zig+8
......@@ -271,6 +271,14 @@ fn compileTimeGlobalReinterpret() {
271271 assert(*d == 1234);
272272}
273273
274fn explicitCastMaybePointers() {
275 @setFnTest(this);
276
277 const a: ?&i32 = undefined;
278 const b: ?&f32 = (?&f32)(a);
279}
280
281
274282// TODO import from std.str
275283pub fn memeql(a: []const u8, b: []const u8) -> bool {
276284 sliceEql(u8, a, b)