diff --git a/vlib/os/process_windows.c.v b/vlib/os/process_windows.c.v index ab3895a78f..190ad06182 100644 --- a/vlib/os/process_windows.c.v +++ b/vlib/os/process_windows.c.v @@ -30,13 +30,8 @@ fn failed_cfn_report_error(ok bool, label string) { exit(1) } -type PU32 = &u32 - -// TODO: the PU32 alias is used to compensate for the wrong number of &/* -// that V does when doing: `h := &&u32(p)`, which should have casted -// p to a double pointer. fn close_valid_handle(p voidptr) { - h := &PU32(p) + h := &&u32(p) if *h != &u32(0) { C.CloseHandle(*h) unsafe { diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index ce9fa1cfb1..f768b6719e 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -848,7 +848,7 @@ fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx if existing_idx == string_type_idx { // existing_type := t.type_symbols[existing_idx] unsafe { - *existing_symbol = &TypeSymbol{ + *existing_symbol = TypeSymbol{ ...typ kind: existing_symbol.kind idx: existing_idx diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 646beae879..db646448a7 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -844,6 +844,12 @@ pub fn (t &TypeSymbol) str() string { return t.name } +// TODO why is this needed? str() returns incorrect amount of & +pub fn (t &TypeSymbol) str_with_correct_nr_muls(n int) string { + prefix := strings.repeat(`&`, n) + return prefix + t.name +} + @[noreturn] fn (t &TypeSymbol) no_info_panic(fname string) { panic('${fname}: no info for type: ${t.name}') diff --git a/vlib/v/checker/assign.v b/vlib/v/checker/assign.v index 5713b79f58..b698bc4f48 100644 --- a/vlib/v/checker/assign.v +++ b/vlib/v/checker/assign.v @@ -186,6 +186,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) { && ((left.info as ast.IdentVar).share == .shared_t || left_type.has_flag(.shared_f)) && c.table.sym(left_type).kind in [.array, .map, .struct] } + if c.comptime.comptime_for_field_var != '' && mut left is ast.ComptimeSelector { if c.comptime.has_different_types && node.right[i].is_literal() && !c.comptime.inside_comptime_if { @@ -545,6 +546,19 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) { c.error('use `${mut_str}array2 ${node.op.str()} array1.clone()` instead of `${mut_str}array2 ${node.op.str()} array1` (or use `unsafe`)', node.pos) } + + // Do not allow auto (de)reference in PrefixExpr + // e.g. `*ptr1 = ptr2` + if mut left is ast.PrefixExpr && left.op == .mul { + if left_type.nr_muls() != right_type.nr_muls() && !left_type.is_voidptr() + && !right_type.is_voidptr() && right_type != ast.nil_type { + r := right_sym.str_with_correct_nr_muls(right_type.nr_muls()) + l := left_sym.str_with_correct_nr_muls(left_type.nr_muls()) + c.error('cannot use `${r}` (right side) as `${l}` (left side) in assignment', + node.pos) + } + } + if left_sym.kind == .array && right_sym.kind == .array { right_info := right_sym.info as ast.Array right_elem_type := c.table.unaliased_type(right_info.elem_type) diff --git a/vlib/v/checker/tests/cannot_dereference_if_different_muls.out b/vlib/v/checker/tests/cannot_dereference_if_different_muls.out new file mode 100644 index 0000000000..ca5331ba08 --- /dev/null +++ b/vlib/v/checker/tests/cannot_dereference_if_different_muls.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/cannot_dereference_if_different_muls.vv:6:8: error: cannot use `&u64` (right side) as `u64` (left side) in assignment + 4 | unsafe { + 5 | mut ptr := &u64(page + higher_half) + 6 | *ptr = freelist_head + | ^ + 7 | freelist_head = ptr + 8 | } diff --git a/vlib/v/checker/tests/cannot_dereference_if_different_muls.vv b/vlib/v/checker/tests/cannot_dereference_if_different_muls.vv new file mode 100644 index 0000000000..4b0e591629 --- /dev/null +++ b/vlib/v/checker/tests/cannot_dereference_if_different_muls.vv @@ -0,0 +1,13 @@ +fn freelist_free(page u64) { + freelist_head := &u64(unsafe { nil }) + higher_half := u64(0) + unsafe { + mut ptr := &u64(page + higher_half) + *ptr = freelist_head + freelist_head = ptr + } +} + +fn main() { + freelist_free(0) +} diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index cb6f2a73bb..c6e74b7583 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -1056,6 +1056,13 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin } } + // Disable parallel checker on arm64 windows and linux for now + $if linux || windows { + $if arm64 { + res.no_parallel = true + } + } + if res.out_name.ends_with('.o') { res.is_o = true }