E3075

E3075 — A C function, declared in an extern block, that takes or returns an i256 or a u256. C passes a 256-bit _BitInt in memory, but this compiler passes a 256-bit integer in registers, so C would read a wrong value. Pass a pointer to the value.

What the compiler reports

Error[E3075] at {{.*}}.vx:[[@LINE+1]]:3: parameter `x` of the C function `takes_wide` is `u256`, and this compiler cannot pass a 256-bit integer to C. Pass a pointer to it
Error[E3075] at {{.*}}.vx:[[@LINE+1]]:3: the C function `gives_wide` returns `i256`, and this compiler cannot get a 256-bit integer from C. Return it through a pointer
2 error(s) emitted

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
//
// C passes a 256-bit `_BitInt` in memory, but Vx passes a `u256` in registers. So a C function
// cannot take or return a `u256` or an `i256`. A `u128` is fine.
//

extern {
  fn takes_wide(x : u256, y : i64) -> i32;
  fn gives_wide() -> i256;
  fn takes_u128(x : u128) -> u128;
}

fn main() -> i32 {
  return 0;
}

From tests/frontend/fail/a_c_function_cannot_take_or_return_a_256_bit_integer.vx, which asserts this diagnostic on every commit.

Related