E3073
E3073 — A C function with a struct parameter or result, used as a value, as in let f = c_function;. C passes a struct in other registers than Vx does, and the type of the value does not say which of the two the function is. So a call through the value would pass the struct the wrong way. Call the C function by its name.
What the compiler reports
Error[E3073] at {{.*}}a_c_function_with_a_struct_is_not_a_function_value.vx:[[@LINE+1]]:{{[0-9]+}}: the C function `take_three` takes or returns a struct, so it cannot be a function value yet. Call it by its name
Error[E3073] at {{.*}}a_c_function_with_a_struct_is_not_a_function_value.vx:[[@LINE+1]]:{{[0-9]+}}: the C function `make_three` takes or returns a struct
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 struct in other registers than Vx does, and the type of a function value does not
// say which of the two the function is. So a C function with a struct parameter or result
// cannot be a function value. A call by its name is fine.
//
struct Three {
a : i64, b : i64, c : i64
}
extern {
fn take_three(t : Three) -> i64;
fn make_three(a : i64) -> Three;
}
fn main() -> i32 {
let _f = take_three;
let _g = make_three;
let t = unsafe { make_three(1) };
return unsafe { take_three(t) } as i32;
}
From tests/frontend/fail/a_c_function_with_a_struct_is_not_a_function_value.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.
E3072Two
extern declarations of one C function with different types. Both name one C symbol, so only one of the types can be right. Declare the function once, or give each declaration the same type. A raw pointer or a reference can point at any type.