Skip to content

Loop invariants cause va_list to fail #7199

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

Closed
feliperodri opened this issue Oct 5, 2022 · 1 comment
Closed

Loop invariants cause va_list to fail #7199

feliperodri opened this issue Oct 5, 2022 · 1 comment
Assignees
Labels
aws Bugs or features of importance to AWS CBMC users bug Code Contracts Function and loop contracts

Comments

@feliperodri
Copy link
Collaborator

CBMC version: 5.67.0
Operating system: N/A

For the following program:

int my_f(int x, ...)
{
  __builtin_va_list list;
  __builtin_va_start(list, x);

  int value;
  unsigned i;

  for(i=0; i<x; i++)
  __CPROVER_loop_invariant (
     list == __CPROVER_loop_entry(list) + i && (value == 10 || i == 0)
  )
  {
    value=__builtin_va_arg(list, int);
  }
  return value;
}

int main()
{
  assert(my_f(1, 10)==10);
}

CBMC fails to prove that the invariant preserves.

I suppose the cause of failure is that __builtin_va_arg(p, int) is statically rewritten to va_args[j] where va_args is the build-in array of arguments. However, after havocing, p becomes a nondet pointer; hence __builtin_va_arg(p, int) cannot be correctly rewritten (and will be rewritten to symex::invalid_object!0#0 as an example).
To resolve the issue, we could rewrite __builtin_va_arg(p, int) to

  1. check if p is the same object as va_args: assert(same_object(p,va_args))
  2. check if the offset of p is valid: assert(offset(p) < object_size(va_args))
  3. substitute __builtin_va_arg(p, int) with (int)(*p)
@feliperodri feliperodri added bug aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts labels Oct 5, 2022
@qinheping
Copy link
Collaborator

qinheping commented Oct 18, 2022

Cannot reproduce the failure now. The issue does not persists. I suppose it is fixed by #6326.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users bug Code Contracts Function and loop contracts
Projects
None yet
Development

No branches or pull requests

2 participants