E3067
E3067 — A read or a write through avoidpointer, as*porp[i]. A*const voidis only an address, for example one thatp as *const voidmade to give to a C function. It has no element type, so the compiler does not know what to read.
What the compiler reports
E3067] at {{.*}}.vx:[[@LINE+15]]:{{[0-9]+}}: Dereferencing a raw pointer needs an element type, and a `void` pointer has none
The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.
A program that triggers it
//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Any pointer can be cast to `*const void` in the same memory, to give its address to a C
// function. A `void` pointer has no element type, so a read or a write through it gets E3067.
// The cast cannot move a pointer into another memory.
//
extern "C" {
fn c_takes_an_address(at : *const void) -> void;
}
fn main() -> i32 {
let numbers = Tensor<f32, [4]>::fill(1.0);
let on_gpu = transfer(Tensor<f32, [4]>::fill(2.0), Memory::GPU_HBM);
let p = numbers.as_ptr() as *const void;
let q = numbers.as_ptr() as *mut void;
unsafe { c_takes_an_address(p); }
let _a = unsafe { *p };
let _b = unsafe { p[0] };
unsafe { *q = 1.0; }
let _c = on_gpu.as_ptr() as *const void;
return 0;
}
From tests/frontend/fail/a_void_pointer_cannot_be_read.vx, which asserts this diagnostic on every commit.
Related
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E3066An
impl in the wrong file, or with the wrong extern. Only the file that declares a struct or an enum writes a plain impl of it. core and std declare the built-in types, such as i32 and Tensor. An impl in another file, for example to break an import cycle, is extern impl, so that a review finds each one. An extern impl in the file of the type is an error too. A macro cannot write extern impl: write it in the file.