|
Hi,
There seems to be something wrong with the way VCC handles the sizeof operator (or at least in the version I'm using; see version info below).
Consider this code fragment:
#include <vcc.h>
void requires_valid_ptr(char* ptr)
_(requires \thread_local(ptr));
int someOffset(int n)
_(ensures \result >= 0 && \result < n) ;
int f(void)
{
char a[10];
int i = someOffset(10);
requires_valid_ptr(&a[i]);
requires_valid_ptr(&a[i-1]);
requires_valid_ptr(&a[i+1]);
}
VCC correctly finds errors on the calls to require_valid_ptr() for &a[i-1] and &a[i+1]:
Verification of f failed. [0,69]
z:\edrdo\mpi\vcc\x.c(15,3) : error VC9502: Call 'requires_valid_ptr(&a[i-1])' did not verify.
z:\edrdo\mpi\vcc\x.c(4,14) : error VC9599: (related information) Precondition: '\thread_local(ptr)'.
z:\edrdo\mpi\vcc\x.c(16,3) : error VC9502: Call 'requires_valid_ptr(&a[i+1])' did not verify.
z:\edrdo\mpi\vcc\x.c(4,14) : error VC9599: (related information) Precondition: '\thread_local(ptr)'.
Verification errors in 1 function(s)
Exiting with 3 (1 error(s).)
However if I use sizeof(a) rather than 10 in the call to someOffset(), vcc reports no errors.
Verification of f succeeded. [0,66]
Any C compiler will interpret sizeof(a) to be equal to 10 in this fragment. What's going on here? Maybe VCC is taking a to be a pointer to char rather than an array address? The version information reported by VCC is :
Microsoft Research Vcc Version 2.3.426.0
Microsoft Research Boogie Version 2.1.40227.0
Microsoft Research Z3 Version Z3 version 3.2
Should I update it?
Thanks, best regards,
Eduardo Marques
|