authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-07 19:08:02-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-07 19:08:02-05:00
logddd9624e2d03b71754e1591637f0f4f835c01a35
tree6f302c1626c0dd2fbbe7d1452affa555e9d9878c
parenteb9f1e2d532aa88199fb6afb3e2cfcef43c2ed14

fix assertion error, trying to dereference to array

thanks to hoppetosse on IRC for reporting the issue

2 files changed, 15 insertions(+), 1 deletions(-)

src/ir.cpp+6-1
...@@ -9399,7 +9399,12 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru...@@ -9399,7 +9399,12 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
9399 if (type_is_invalid(value->value.type))9399 if (type_is_invalid(value->value.type))
9400 return value->value.type;9400 return value->value.type;
94019401
9402 assert(ptr->value.type->id == TypeTableEntryIdPointer);9402 if (ptr->value.type->id != TypeTableEntryIdPointer) {
9403 ir_add_error(ira, ptr,
9404 buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));
9405 return ira->codegen->builtin_types.entry_invalid;
9406 }
9407
9403 if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) {9408 if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) {
9404 return ir_analyze_void(ira, &store_ptr_instruction->base);9409 return ir_analyze_void(ira, &store_ptr_instruction->base);
9405 }9410 }
test/run_tests.cpp+9
...@@ -1704,6 +1704,15 @@ fn foo() {...@@ -1704,6 +1704,15 @@ fn foo() {
1704 while (i < 10; i += 1) { }1704 while (i < 10; i += 1) { }
1705}1705}
1706 )SOURCE", 1, ".tmp_source.zig:3:5: error: unable to infer variable type");1706 )SOURCE", 1, ".tmp_source.zig:3:5: error: unable to infer variable type");
1707
1708 add_compile_fail_case("dereference an array", R"SOURCE(
1709var s_buffer: [10]u8 = undefined;
1710pub fn pass(in: []u8) -> []u8 {
1711 var out = &s_buffer;
1712 *out[0] = in[0];
1713 return (*out)[0...1];
1714}
1715 )SOURCE", 1, ".tmp_source.zig:5:5: error: attempt to dereference non pointer type '[10]u8'");
1707}1716}
17081717
1709//////////////////////////////////////////////////////////////////////////////1718//////////////////////////////////////////////////////////////////////////////