E3067

E3067 — A read or a write through a void pointer, as *p or p[i]. A *const void is only an address, for example one that p as *const void made 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