authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-05 22:23:23-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-05 23:26:43-04:00
logbd13e757e7e36994d2a1fd4595c617d14e22b7c6
tree956870c725e4cf9f9a8097204c2a93ac18a9f409
parent0ccc18686921dce8e7f2feb95eed83b894ca8df4

disable deref syntax for unknown length pointers

See #770

3 files changed, 22 insertions(+), 1 deletions(-)

src/ir.cpp+12
......@@ -11132,7 +11132,13 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1113211132
1113311133static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
1113411134 IrInstruction *op1 = bin_op_instruction->op1->other;
11135 if (type_is_invalid(op1->value.type))
11136 return ira->codegen->builtin_types.entry_invalid;
11137
1113511138 IrInstruction *op2 = bin_op_instruction->op2->other;
11139 if (type_is_invalid(op2->value.type))
11140 return ira->codegen->builtin_types.entry_invalid;
11141
1113611142 IrBinOp op_id = bin_op_instruction->op_id;
1113711143
1113811144 // look for pointer math
......@@ -12851,6 +12857,12 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
1285112857 if (type_is_invalid(ptr_type)) {
1285212858 return ira->codegen->builtin_types.entry_invalid;
1285312859 } else if (ptr_type->id == TypeTableEntryIdPointer) {
12860 if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
12861 ir_add_error_node(ira, un_op_instruction->base.source_node,
12862 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
12863 buf_ptr(&ptr_type->name)));
12864 return ira->codegen->builtin_types.entry_invalid;
12865 }
1285412866 child_type = ptr_type->data.pointer.child_type;
1285512867 } else {
1285612868 ir_add_error_node(ira, un_op_instruction->base.source_node,
std/special/bootstrap.zig+1-1
......@@ -51,7 +51,7 @@ extern fn WinMainCRTStartup() noreturn {
5151
5252// TODO https://github.com/ziglang/zig/issues/265
5353fn posixCallMainAndExit() noreturn {
54 const argc = argc_ptr.*;
54 const argc = argc_ptr[0];
5555 const argv = @ptrCast([*][*]u8, argc_ptr + 1);
5656
5757 const envp_nullable = @ptrCast([*]?[*]u8, argv + argc + 1);
test/compile_errors.zig+9
......@@ -1,6 +1,15 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "dereference unknown length pointer",
6 \\export fn entry(x: [*]i32) i32 {
7 \\ return x.*;
8 \\}
9 ,
10 ".tmp_source.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'",
11 );
12
413 cases.add(
514 "field access of unknown length pointer",
615 \\const Foo = extern struct {