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 *...@@ -11132,7 +11132,13 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
1113211132
11133static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {11133static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
11134 IrInstruction *op1 = bin_op_instruction->op1->other;11134 IrInstruction *op1 = bin_op_instruction->op1->other;
11135 if (type_is_invalid(op1->value.type))
11136 return ira->codegen->builtin_types.entry_invalid;
11137
11135 IrInstruction *op2 = bin_op_instruction->op2->other;11138 IrInstruction *op2 = bin_op_instruction->op2->other;
11139 if (type_is_invalid(op2->value.type))
11140 return ira->codegen->builtin_types.entry_invalid;
11141
11136 IrBinOp op_id = bin_op_instruction->op_id;11142 IrBinOp op_id = bin_op_instruction->op_id;
1113711143
11138 // look for pointer math11144 // look for pointer math
...@@ -12851,6 +12857,12 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp...@@ -12851,6 +12857,12 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
12851 if (type_is_invalid(ptr_type)) {12857 if (type_is_invalid(ptr_type)) {
12852 return ira->codegen->builtin_types.entry_invalid;12858 return ira->codegen->builtin_types.entry_invalid;
12853 } else if (ptr_type->id == TypeTableEntryIdPointer) {12859 } 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 }
12854 child_type = ptr_type->data.pointer.child_type;12866 child_type = ptr_type->data.pointer.child_type;
12855 } else {12867 } else {
12856 ir_add_error_node(ira, un_op_instruction->base.source_node,12868 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 {...@@ -51,7 +51,7 @@ extern fn WinMainCRTStartup() noreturn {
5151
52// TODO https://github.com/ziglang/zig/issues/26552// TODO https://github.com/ziglang/zig/issues/265
53fn posixCallMainAndExit() noreturn {53fn posixCallMainAndExit() noreturn {
54 const argc = argc_ptr.*;54 const argc = argc_ptr[0];
55 const argv = @ptrCast([*][*]u8, argc_ptr + 1);55 const argv = @ptrCast([*][*]u8, argc_ptr + 1);
5656
57 const envp_nullable = @ptrCast([*]?[*]u8, argv + argc + 1);57 const envp_nullable = @ptrCast([*]?[*]u8, argv + argc + 1);
test/compile_errors.zig+9
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub 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
4 cases.add(13 cases.add(
5 "field access of unknown length pointer",14 "field access of unknown length pointer",
6 \\const Foo = extern struct {15 \\const Foo = extern struct {