[sledge] Update tests

Reviewed By: jvillard

Differential Revision: D25756547

fbshipit-source-id: eecb98e6a
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent af980bafa0
commit dc3d67d5cc

@ -0,0 +1,20 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
void main() {
size_t n = __llair_choice();
n = (n < 0 ? -n : n) + 1;
int* a = __llair_alloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
a[i] = i;
}
free(a);
return;
}

@ -0,0 +1,32 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <cstddef>
#include <cstdint>
extern "C" int mallctl(const char* name, void* oldp, size_t* oldlenp,
void* newp, size_t newlen) __attribute__((__weak__));
int main() {
volatile uint64_t* counter;
size_t counterLen = sizeof(uint64_t*);
if (mallctl("thread.allocatedp", static_cast<void*>(&counter), &counterLen,
nullptr, 0) != 0) {
return 1;
}
if (counterLen != sizeof(uint64_t*)) {
return 1;
}
// false alarm: the spec of mallctl does not special case
// thread.allocatedp and set counter to a valid pointer
uint64_t origAllocated = *counter;
return 0;
}

@ -0,0 +1,16 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int main() {
auto x = new int[8];
auto y = new int[8];
y[0] = 42;
auto x_ptr = x + 8; // one past the end
if (x_ptr == &y[0]) // valid
*x_ptr = 23; // UB
return y[0];
}

@ -0,0 +1,25 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
typedef struct _ {
int x;
int y;
} S;
S s;
void main() {
int x, y, z;
S* p;
x = (&s)->x;
p = &s;
y = p->x;
z = s.x;
return;
}

@ -0,0 +1,22 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
typedef struct _ {
int* f;
int* g;
} S;
void main() {
S x;
int** p;
int y;
/* safe */
x.f = &y;
p = &x.f;
p++;
}

@ -0,0 +1,25 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
typedef struct _ {
int* f;
int* g;
} S;
void main() {
S x;
int** p;
int y;
/* safe */
x.f = &y;
p = &x.f;
p++;
/* unsafe */
*p = 0;
*x.g = 0;
}

@ -9,6 +9,7 @@ float f(int x, float y) { // 8, 3.0
int z = x * x; // 64 int z = x * x; // 64
return y + z; // 67.0 return y + z; // 67.0
} }
int g(int y) { // 8 int g(int y) { // 8
if (y) { if (y) {
return 1; return 1;

@ -5,17 +5,16 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include <stdlib.h> // for exit
int f(int x); int f(int x);
int g(int x); int g(int x);
int f(int x) { // x= 0, 1, 2, ... int f(int x) { // x= 0, 1, 2, ...
return g(x + 2); return g(x + 2);
} }
int g(int y) { // y= 2, 3, 4, ... int g(int y) { // y= 2, 3, 4, ...
if (y > 5) { // catch this crash only when depth bound > 2 if (y > 5) {
exit(42); return y;
} }
return f(y - 1); // Back edge! return f(y - 1); // Back edge!
} }

@ -0,0 +1,25 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int f(int x);
int g(int x);
int f(int x) { // x= 0, 1, 2, ...
return g(x + 2);
}
int g(int y) { // y= 2, 3, 4, ...
if (y > 5) { // catch this crash only when depth bound >= 4
abort();
}
return f(y - 1); // Back edge!
}
int main() {
f(0);
return 0;
}

@ -0,0 +1,18 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int x;
void main() {
int n = 4;
int* A = (int*)__llair_alloc(n * sizeof(int));
/* safe */
x = A[0];
x = A[1];
x = A[2];
x = A[3];
}

@ -0,0 +1,21 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int x;
void main() {
int n = 4;
int* A = (int*)__llair_alloc(n * sizeof(int));
/* safe */
x = A[0];
x = A[1];
x = A[2];
x = A[3];
/* unsafe */
x = A[-2];
x = A[n + 2];
}

@ -0,0 +1,17 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <assert.h>
int main() {
int two;
int equals_two;
two = 2;
equals_two = (two == 2);
assert((equals_two != 0));
assert((equals_two == 1));
}

@ -0,0 +1,19 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
typedef struct _ {
int i;
int j;
char c;
} S;
void main() {
S x = {1, 2, '3'};
S y = {4, 5, '6'};
x = y;
}

@ -0,0 +1,12 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int main() {
int* p = (int*)malloc(sizeof(int));
free(p);
free(p);
}

@ -0,0 +1,11 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int main() {
int i;
free(&i);
}

@ -5,24 +5,13 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
/* The symbolic heap for this example should look like:
^ %.str --> <13,{}> * %c1 --> <8,%.str> * %retval --> <4,0>
instead of
^ %.str --> <13,{}>
* %a_string --> <8,%.str>
* %an_int --> <4,0>
* %c1 --> <8,%.str>
* %retval --> <4,0>
Which has an_int and a_string indirections. There can be obtained by
sledge.dbg llvm analyze -trace Domain.call global_vars.bc */
const char* a_string = "I'm a string"; const char* a_string = "I'm a string";
int an_int = 0; int an_int = 0;
int c() { return an_int; } int idx() { return an_int; }
int main() { int main() {
const char* c1 = a_string; const char* str = a_string;
return c(); return str[idx()];
} }

@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int main() {
int c = __llair_choice() % 5;
int* p;
if (c) {
p = (int*)malloc(sizeof(int));
}
for (int i = 0; i < 4; i++) {
c += (__llair_choice() % 3);
}
if (c) {
*p = 0;
free(p);
}
return 0;
}

@ -0,0 +1,26 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
void main() {
int x, y;
x++;
if (x / 2) {
L0:
if (x <= 0)
goto L3;
x--;
goto L1;
} else {
L1:
y++;
goto L0;
}
L3:
return;
}

@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int main() {
int n = 0;
int b = __llair_choice();
for (int i = 0; i < b; i++) {
n += i;
}
return n;
}

@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int main() {
int x = 0;
while (__llair_choice()) {
x += 1;
while (__llair_choice()) {
x += 3;
if (__llair_choice()) {
x += 5;
} else {
x += 7;
}
x += 9;
}
}
return x;
}

@ -0,0 +1,24 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
int main() {
int x = 0;
while (__llair_choice()) {
x += 1;
while (__llair_choice()) {
x += 3;
if (__llair_choice()) {
x += 5;
} else {
x += 7;
}
if (__llair_choice())
break;
}
}
return x;
}

@ -4,33 +4,32 @@
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include <stdio.h>
char* a = "I'm a string"; char* a = "I'm a string";
char* b = "I'm a different string"; char* b = "I'm a different string";
char* c = "foo bar"; char* c = "foo bar";
char* d = "hello world"; char* d = "hello world";
FILE* file;
void f(); void f();
void g(); void g();
int main() { // accesses: a,b,c,d
if (getc(file)) { // nondeterministic
f();
} else {
g();
}
char* s = a;
return 0;
}
void f() { // accesses: b, c, d void f() { // accesses: b, c, d
char* s1 = b; char* s1 = b;
g(); g();
char* s2 = c; char* s2 = c;
} }
void g() { // accesses: b, c, d void g() { // accesses: b, c, d
char* s = d; char* s = d;
f(); f();
} }
int main() { // accesses: a,b,c,d
if (__llair_choice()) {
f();
} else {
g();
}
char* s = a;
return 0;
}

@ -0,0 +1,22 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <memory>
#include <vector>
std::shared_ptr<std::vector<int>> get() {
std::vector<int> v = {1, 2, 3};
return std::make_shared<std::vector<int>>(v);
}
int main() {
int n;
for (auto& t : *get()) {
n += t;
}
return n;
}

@ -5,12 +5,11 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
/* Simple mutual recursion. Sledge should respect execution
* bounds and terminate quickly for small bounds */
void mutal_rec_d(); void mutal_rec_d();
void mutal_rec_a() { mutal_rec_d(); } void mutal_rec_a() { mutal_rec_d(); }
void mutal_rec_d() { mutal_rec_a(); } void mutal_rec_d() { mutal_rec_a(); }
void recurse() { recurse(); } void recurse() { recurse(); }
int main() { int main() {
recurse(); recurse();
mutal_rec_a(); mutal_rec_a();

@ -0,0 +1,17 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
typedef struct _ {
int x;
int a[30];
} S;
int main() {
S s;
s = s;
return s.x;
}

@ -0,0 +1,40 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
struct B {
void foo() {}
~B() {
if (!i_) {
foo();
}
}
int i_;
};
struct A {
~A() {
if (b_) {
b_->foo();
}
}
B* b_{nullptr};
};
struct S {
S() { a.b_ = &b; }
A a;
B b;
};
int main(int argc, char* argv[]) {
S s;
return 0;
}
int _llair_main() { return main(0, nullptr); }

@ -8,6 +8,7 @@
#include <stdlib.h> #include <stdlib.h>
char* c() { return malloc(12); } char* c() { return malloc(12); }
int main() { int main() {
char* s = c(); char* s = c();
return s ? *s : 1; return s ? *s : 1;

Loading…
Cancel
Save