Reviewed By: jvillard Differential Revision: D25756547 fbshipit-source-id: eecb98e6amaster
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;
|
||||
}
|
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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); }
|
Loading…
Reference in new issue