diff --git a/src/ir.cpp b/src/ir.cpp index 5c44e7c0ff..a6686aae76 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11132,7 +11132,13 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { IrInstruction *op1 = bin_op_instruction->op1->other; + if (type_is_invalid(op1->value.type)) + return ira->codegen->builtin_types.entry_invalid; + IrInstruction *op2 = bin_op_instruction->op2->other; + if (type_is_invalid(op2->value.type)) + return ira->codegen->builtin_types.entry_invalid; + IrBinOp op_id = bin_op_instruction->op_id; // look for pointer math @@ -12851,6 +12857,12 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp if (type_is_invalid(ptr_type)) { return ira->codegen->builtin_types.entry_invalid; } else if (ptr_type->id == TypeTableEntryIdPointer) { + if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) { + ir_add_error_node(ira, un_op_instruction->base.source_node, + buf_sprintf("index syntax required for unknown-length pointer type '%s'", + buf_ptr(&ptr_type->name))); + return ira->codegen->builtin_types.entry_invalid; + } child_type = ptr_type->data.pointer.child_type; } else { ir_add_error_node(ira, un_op_instruction->base.source_node, diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index 64eae79ce4..8aefe4751f 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -51,7 +51,7 @@ extern fn WinMainCRTStartup() noreturn { // TODO https://github.com/ziglang/zig/issues/265 fn posixCallMainAndExit() noreturn { - const argc = argc_ptr.*; + const argc = argc_ptr[0]; const argv = @ptrCast([*][*]u8, argc_ptr + 1); const envp_nullable = @ptrCast([*]?[*]u8, argv + argc + 1); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index ab539dd94a..412b2d5fc9 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1,6 +1,15 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "dereference unknown length pointer", + \\export fn entry(x: [*]i32) i32 { + \\ return x.*; + \\} + , + ".tmp_source.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", + ); + cases.add( "field access of unknown length pointer", \\const Foo = extern struct {