mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
checker: do not allow auto (de)reference in PrefixExpr *; pref: disable parallel checker on arm linux for now
This commit is contained in:
parent
4422662b07
commit
bed827e663
7 changed files with 49 additions and 7 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}')
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 | }
|
13
vlib/v/checker/tests/cannot_dereference_if_different_muls.vv
Normal file
13
vlib/v/checker/tests/cannot_dereference_if_different_muls.vv
Normal file
|
@ -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)
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue