Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion between two function-types instantiations in an indirect call #23

Open
necto opened this issue Apr 20, 2016 · 2 comments
Open

Comments

@necto
Copy link
Contributor

necto commented Apr 20, 2016

When I have a generic function type, and two instantiations for different type-arguments, VeriFast searches for a wrong is_... predicate instance:

typedef int fun/*@ <t>(predicate (void*;t) pred) @*/(void* p);
//@ requires pred(p, ?x);
//@ ensures pred(p, x);

int f1(void* p)
//@ requires integer(p, ?x);
//@ ensures integer(p, x);
{
  return 0;
}

int f2(void* p)
//@ requires character(p, ?x);
//@ ensures character(p, x);
{
  return 1;
}

void caller()
//@ requires true;
//@ ensures true;
{
  /*@ produce_function_pointer_chunk fun<int>(f1)(integer)(x)
      {
        call();
      }
    @*/
  /*@ produce_function_pointer_chunk fun<char>(f2)(character)(x)
      {
        call();
      }
    @*/
  fun* a = f1;
  fun* b = f2;
  int c = '.';
  int x = a(&c); //<-- here
}

The report is: "No matching heap chunks: is_fun(f1, _)"

While it should really call using is_fun<int>(f1,_)

@necto necto changed the title Confusion between two function-types instantiations Confusion between two function-types instantiations in an indirect call Apr 20, 2016
@btj
Copy link
Member

btj commented May 17, 2016

You can work around this by hiding the is_fun<char>(f2, _) chunk before the call of f1, by wrapping it inside a helper predicate (which you can define as a block-local predicate inside caller so that it can use local variables).

@necto
Copy link
Contributor Author

necto commented May 18, 2016

That works, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants