E3075
E3075 — A C function, declared in anexternblock, that takes or returns ani256or au256. C passes a 256-bit_BitIntin 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
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E3074A call of
String::from_literal whose argument is not a string literal. The argument can also be a let without mut whose value is a string literal. The call needs no unsafe because the compiler makes each literal, so it knows that the bytes are a C string. It does not know that for another pointer. For such a pointer, call String::from_c_str in unsafe code.