E8011
E8011 — A pointer clause that is not well formed:valid(p, n),initialized(p, n)or!overlaps(p, q, n), wherepandqare raw pointer parameters, and each clause is arequiresor anensuresof its own. In anensures,returncan be the pointer. The fact of anassumeis one such clause. A call through a function value or a trait would not prove arequires, so a safe function with one cannot be a function value, and a safe method of a trait impl cannot have one. Afreesclause is anensuresof its own,ensures frees(p)orensures !frees(p)for a parameterp, and a method of a trait impl cannot add a!freesthat the trait method does not have. Anexternfunction can also ensure a clause about numbers that names only its integer parameters andreturn.
What the compiler reports
Error[E8011] at {{.*}}.vx:[[@LINE+2]]:{{[0-9]+}}: an `extern` function can have only a `frees` clause, a pointer clause or a clause about numbers in its `ensures`
Error[E8006] at {{.*}}.vx:[[@LINE+1]]:10: this call to 'in_range'
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
//
// A call of an `extern` function knows only what its `ensures` say. An `ensures` about numbers
// can name only the parameters and `return`.
//
extern "C" {
safe fn c_count(n : i64) -> i64;
safe fn c_other(n : i64) -> i64
ensures 0i64 <= m;
}
fn in_range(got : i64, n : i64) -> i64
requires 0i64 <= got && got <= n
{
return got;
}
fn main() -> i32 {
let n = 8i64;
let got = c_count(n);
return in_range(got, n) as i32;
}
From tests/frontend/fail/an_extern_function_that_ensures_no_number.vx, which asserts this diagnostic on every commit.
Related
Contracts and verificationThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E8010An
mlir! block whose dialects list does not match its body: the body uses an operation of a dialect that the list does not name, or the list names something that is not a dialect. The list is what the block says it uses, so it must be right.
E8012A body that breaks a pointer ensures of its function. The facts at a return, or at the end of the body, do not prove a clause such as ensures valid(return, n). Or the body changes a parameter that such a clause names. Or the function says ensures !frees(p), and its body gives p, or a value that it gets from p, to code that can free memory, such as a call without !frees for that parameter, a store or an mlir! block.