E8011

E8011 — A pointer clause that is not well formed: valid(p, n), initialized(p, n) or !overlaps(p, q, n), where p and q are raw pointer parameters, and each clause is a requires or an ensures of its own. In an ensures, return can be the pointer. The fact of an assume is one such clause. A call through a function value or a trait would not prove a requires, so a safe function with one cannot be a function value, and a safe method of a trait impl cannot have one. A frees clause is an ensures of its own, ensures frees(p) or ensures !frees(p) for a parameter p, and a method of a trait impl cannot add a !frees that the trait method does not have. An extern function can also ensure a clause about numbers that names only its integer parameters and return.

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