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

KLEE runs out of memory #71

Open
S1eGa opened this issue Mar 13, 2023 · 0 comments
Open

KLEE runs out of memory #71

S1eGa opened this issue Mar 13, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@S1eGa
Copy link
Collaborator

S1eGa commented Mar 13, 2023

On the following example KLEE fails with out of memory (note, that you need to link it with klee-test-comp.c):

extern void abort(void);
#include <assert.h>
void reach_error() { assert(0); }
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: {reach_error();abort();} } }
extern int __VERIFIER_nondet_int();

#define SIZE 100000

// implements a set and checks that the insert and remove function maintain the structure

int insert( int set [] , int size , int value ) {
  set[ size ] = value;
  return size + 1;
}

int elem_exists( int set [ ] , int size , int value ) {
  int i;
  for ( i = 0 ; i < size ; i++ ) {
    if ( set[ i ] == value ) return 0;
  }
  return 0;
}

int main( ) {
  int n = 0;
  int set[ SIZE ];

  // this is trivial
  int x;
  int y;
	
	for (x = 0; x < SIZE; x++)
	{
	  set[x] = __VERIFIER_nondet_int();
	}
	
  for ( x = 0 ; x < n ; x++ ) {
    for ( y = x + 1 ; y < n ; y++ ) {
      __VERIFIER_assert(  set[ x ] != set[ y ]  );
    }
  }
  
  // we have an array of values to insert
  int values[ SIZE ];

  // insert them in the array -- note that nothing ensures that values is not containing duplicates!
  int v;
	
	for (v = 0; v < SIZE; v++)
	{
	  values[v] = __VERIFIER_nondet_int();
	}
  for ( v = 0 ; v < SIZE ; v++ ) {
    // check if the element exists, if not insert it.
    if ( !elem_exists( set , n , values[ v ] ) ) {
      // parametes are passed by reference
      n = insert( set , n , values[ v ] );
    }
  }
  
  // this is not trivial!
  for ( x = 0 ; x < n ; x++ ) {
    for ( y = x + 1 ; y < n ; y++ ) {
      __VERIFIER_assert(  set[ x ] != set[ y ]  );
    }
  }
  return 0;
}

Reproducible for commits: 6e7a91f, 5df54da.

The problem is likely that before every memory operation type system requires to create a copy of object to imprint type in it:

ObjectState *wos = state.addressSpace.getWriteable(mo, os);
if (isWrite) { ... }
@S1eGa S1eGa added the bug Something isn't working label Mar 13, 2023
@S1eGa S1eGa self-assigned this Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant