Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ziglang/zig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bbb565a21e40
Choose a base ref
...
head repository: ziglang/zig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bd13e757e7e3
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jun 6, 2018

  1. Copy the full SHA
    0ccc186 View commit details
  2. Copy the full SHA
    bd13e75 View commit details
Showing with 37 additions and 3 deletions.
  1. +2 −2 src/analyze.cpp
  2. +12 −0 src/ir.cpp
  3. +1 −1 std/special/bootstrap.zig
  4. +22 −0 test/compile_errors.zig
4 changes: 2 additions & 2 deletions src/analyze.cpp
Original file line number Diff line number Diff line change
@@ -3753,13 +3753,13 @@ static bool is_container(TypeTableEntry *type_entry) {
}

bool is_container_ref(TypeTableEntry *type_entry) {
return (type_entry->id == TypeTableEntryIdPointer) ?
return (type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle) ?
is_container(type_entry->data.pointer.child_type) : is_container(type_entry);
}

TypeTableEntry *container_ref_type(TypeTableEntry *type_entry) {
assert(is_container_ref(type_entry));
return (type_entry->id == TypeTableEntryIdPointer) ?
return (type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle) ?
type_entry->data.pointer.child_type : type_entry;
}

12 changes: 12 additions & 0 deletions src/ir.cpp
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion std/special/bootstrap.zig
Original file line number Diff line number Diff line change
@@ -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);
22 changes: 22 additions & 0 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
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 {
\\ a: i32,
\\};
\\
\\export fn entry(foo: [*]Foo) void {
\\ foo.a += 1;
\\}
,
".tmp_source.zig:6:8: error: type '[*]Foo' does not support field access",
);

cases.add(
"unknown length pointer to opaque",
\\export const T = [*]@OpaqueType();