Skip to content

__CPROVER_w_ok has weird behaviour #5194

@danielsn

Description

@danielsn

Since y > x, it should be true that !__CPROVER_w_ok(a, y) is always false. However, if you assert this fact, you get an assertion violation.

#include<assert.h>
#include<stdlib.h>
#include<stdint.h>

int main() {
  size_t x;
  size_t y;
  uint8_t* a;

  __CPROVER_assume(x > 0);
  __CPROVER_assume(y > x);

  a = malloc(sizeof(*(a)) * (x));

  assert(!__CPROVER_w_ok(a, y));
}
~/temp $ cbmc *.c --trace --pointer-check --bounds-check
CBMC version 5.12 (cbmc-5.12-d8598f8-1008-gfab409d18) 64-bit x86_64 macos
Parsing test.c
Converting
Type-checking test
Generating GOTO Program
Adding CPROVER library (x86_64)
Removal of function pointers and virtual functions
Generic Property Instrumentation
Running with 8 object bits, 56 offset bits (default)
Starting Bounded Model Checking
size of program expression: 70 steps
simple slicing removed 5 assignments
Generated 1 VCC(s), 1 remaining after simplification
Passing problem to propositional reduction
converting SSA
Running propositional reduction
Post-processing
Solving with MiniSAT 2.2.1 with simplifier
874 variables, 2035 clauses
SAT checker: instance is SATISFIABLE
Runtime decision procedure: 0.00674373s
Building error trace

** Results:
test.c function main
[main.assertion.1] line 15 assertion !__CPROVER_w_ok(a, y): FAILURE

Trace for main.assertion.1:

State 21 file test.c function main line 6 thread 0
----------------------------------------------------
  x=35235878141952ul (00000000 00000000 00100000 00001011 11111110 00000000 00000000 00000000)

State 22 file test.c function main line 7 thread 0
----------------------------------------------------
  y=36028814198833152ul (00000000 10000000 00000000 00000100 00000000 00000000 00000000 00000000)

State 23 file test.c function main line 8 thread 0
----------------------------------------------------
  a=((uint8_t *)NULL) (00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000)

Assumption:
  file test.c line 10 function main
  x > (unsigned long int)0

Assumption:
  file test.c line 11 function main
  y > x

State 29 file test.c function main line 13 thread 0
----------------------------------------------------
  malloc_size=35235878141952ul (00000000 00000000 00100000 00001011 11111110 00000000 00000000 00000000)

State 48 file test.c function main line 13 thread 0
----------------------------------------------------
  a=dynamic_object1 (00000010 00000000 00000000 00000000 00000000 00000000 00000000 00000000)

Violated property:
  file test.c function main line 15 thread 0
  assertion !__CPROVER_w_ok(a, y)
  !((signed long int)(signed long int)!(!((FALSE || !(POINTER_OBJECT((const void *)a) == POINTER_OBJECT(NULL))) && !IS_INVALID_POINTER((const void *)a) && (FALSE || !(POINTER_OBJECT((const void *)a) == POINTER_OBJECT(__CPROVER_deallocated))) && (FALSE || !(POINTER_OBJECT((const void *)a) == POINTER_OBJECT(__CPROVER_dead_object))) && (FALSE || (POINTER_OBJECT((const void *)a) == POINTER_OBJECT(__CPROVER_malloc_object) ==> !(POINTER_OFFSET((const void *)a) < 0l || (size_t)POINTER_OFFSET((const void *)a) + y > __CPROVER_malloc_size))) && (FALSE || (!IS_DYNAMIC_OBJECT((const void *)a) ==> !(POINTER_OFFSET((const void *)a) < 0l || (size_t)POINTER_OFFSET((const void *)a) + y > OBJECT_SIZE((const void *)a)))) && (POINTER_OBJECT(NULL) == POINTER_OBJECT((const void *)a) && NULL != (const void *)a ==> FALSE))) != 0l)



** 1 of 1 failed (2 iterations)
VERIFICATION FAILED
~/temp $ cbmc --version
5.12 (cbmc-5.12-d8598f8-1008-gfab409d18)
~/temp $ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G1012

Metadata

Metadata

Assignees

No one assigned

    Labels

    awsBugs or features of importance to AWS CBMC users

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions