#include "Inputs/system-header-simulator-cxx.h"
void clang_analyzer_warnIfReached();
void clang_analyzer_printState();
class B {
public:
B() = default;
B(const B &) = default;
B(B &&) = default;
B& operator=(const B &q) = default;
void operator=(B &&b) {
return;
}
void foo() { return; }
};
class A {
int i;
double d;
public:
B b;
A(int ii = 42, double dd = 1.0) : d(dd), i(ii), b(B()) {}
void moveconstruct(A &&other) {
std::swap(b, other.b);
std::swap(d, other.d);
std::swap(i, other.i);
return;
}
static A get() {
A v(12, 13);
return v;
}
A(A *a) {
moveconstruct(std::move(*a));
}
A(const A &other) : i(other.i), d(other.d), b(other.b) {}
A(A &&other) : i(other.i), d(other.d), b(std::move(other.b)) { }
A(A &&other, char *k) {
moveconstruct(std::move(other));
}
void operator=(const A &other) {
i = other.i;
d = other.d;
b = other.b;
return;
}
void operator=(A &&other) {
moveconstruct(std::move(other));
return;
}
int getI() { return i; }
int foo() const;
void bar() const;
void reset();
void destroy();
void clear();
void resize(std::size_t);
void assign(const A &);
bool empty() const;
bool isEmpty() const;
operator bool() const;
void testUpdateField() {
A a;
A b = std::move(a);
a.i = 1;
a.foo(); }
void testUpdateFieldDouble() {
A a;
A b = std::move(a);
a.d = 1.0;
a.foo(); }
};
int bignum();
void moveInsideFunctionCall(A a) {
A b = std::move(a);
}
void leftRefCall(A &a) {
a.foo();
}
void rightRefCall(A &&a) {
a.foo();
}
void constCopyOrMoveCall(const A a) {
a.foo();
}
void copyOrMoveCall(A a) {
a.foo();
}
void simpleMoveCtorTest() {
{
A a;
A b = std::move(a);
#ifdef AGGRESSIVE_DFS
clang_analyzer_printState();
#endif
a.foo(); }
{
A a;
A b = std::move(a); b = a; }
{
A a;
A b = std::move(a); b = std::move(a); }
}
void simpleMoveAssignementTest() {
{
A a;
A b;
b = std::move(a); a.foo(); }
{
A a;
A b;
b = std::move(a); A c(a); }
{
A a;
A b;
b = std::move(a); A c(std::move(a)); }
}
void moveInInitListTest() {
struct S {
A a;
};
A a;
S s{std::move(a)}; a.foo(); }
void reinitializationTest(int i) {
{
A a;
A b;
b = std::move(a);
a = A();
a.foo();
}
{
A a;
if (i == 1) { A b;
b = std::move(a);
a = A();
}
if (i == 2) { a.foo(); }
}
{
A a;
if (i == 1) { (void)std::move(a);
}
if (i == 2) { a = A();
a.foo();
}
}
{
int a1 = 1, a2 = 2;
std::swap(a1, a2);
}
{
A a;
A b;
b = std::move(a);
a = A();
b = std::move(a); a.foo(); }
{
A a;
A b;
b = std::move(a); if (i < 10) { a = A();
}
if (i > 5) { a.foo(); }
}
}
void decltypeIsNotUseTest() {
A a;
decltype(a) other_a; }
void loopTest() {
{
A a;
for (int i = 0; i < bignum(); i++) { rightRefCall(std::move(a)); }
}
{
A a;
for (int i = 0; i < 2; i++) { rightRefCall(std::move(a)); }
}
{
A a;
for (int i = 0; i < bignum(); i++) { leftRefCall(a); }
}
{
A a;
for (int i = 0; i < 2; i++) { leftRefCall(a); }
}
{
A a;
for (int i = 0; i < bignum(); i++) { constCopyOrMoveCall(a); }
}
{
A a;
for (int i = 0; i < 2; i++) { constCopyOrMoveCall(a); }
}
{
A a;
for (int i = 0; i < bignum(); i++) { moveInsideFunctionCall(a); }
}
{
A a;
for (int i = 0; i < 2; i++) { moveInsideFunctionCall(a); }
}
{
A a;
for (int i = 0; i < bignum(); i++) { copyOrMoveCall(a); }
}
{
A a;
for (int i = 0; i < 2; i++) { copyOrMoveCall(a); }
}
{
A a;
for (int i = 0; i < bignum(); i++) { constCopyOrMoveCall(std::move(a)); }
}
{
A a;
for (int i = 0; i < 3; ++i) {
a.bar();
if (a.foo() > 0) {
A b;
b = std::move(a); return;
}
}
}
}
void uniqueTest(bool cond) {
A a(42, 42.0);
A b;
b = std::move(a);
if (cond) { a.foo(); }
if (cond) {
a.bar(); }
a.bar(); }
void uniqueTest2() {
A a;
A a1 = std::move(a); a.foo();
A a2 = std::move(a); a.foo(); }
void moveSafeFunctionsTest() {
A a;
A b = std::move(a); a.empty(); a.isEmpty(); (void)a; (bool)a; a.foo(); }
void moveStateResetFunctionsTest() {
{
A a;
A b = std::move(a);
a.reset(); a.foo(); a.b.foo(); }
{
A a;
A b = std::move(a);
a.destroy(); a.foo(); }
{
A a;
A b = std::move(a);
a.clear(); a.foo(); a.b.foo(); }
{
A a;
A b = std::move(a);
a.resize(0); a.foo(); a.b.foo(); }
{
A a;
A b = std::move(a);
a.assign(A()); a.foo(); a.b.foo(); }
}
template <int>
class ClassTemplate {
public:
void foo(A a);
};
template <int>
void functionTemplate(A a);
void templateArgIsNotUseTest() {
{
A a;
ClassTemplate<sizeof(A(std::move(a)))>().foo(std::move(a)); }
{
A a;
functionTemplate<sizeof(A(std::move(a)))>(std::move(a)); }
}
A global_a;
void globalVariablesTest() {
(void)std::move(global_a);
global_a.foo(); }
class memberVariablesTest {
A a;
static A static_a;
void f() {
A b;
b = std::move(a);
a.foo();
b = std::move(static_a); static_a.foo(); }
};
void PtrAndArrayTest() {
A *Ptr = new A(1, 1.5);
A Arr[10];
Arr[2] = std::move(*Ptr); (*Ptr).foo();
Ptr = &Arr[1];
Arr[3] = std::move(Arr[1]); Ptr->foo();
Arr[3] = std::move(Arr[2]); Arr[2].foo();
Arr[2] = std::move(Arr[3]); Arr[2].foo(); }
void exclusiveConditionsTest(bool cond) {
A a;
if (cond) {
A b;
b = std::move(a);
}
if (!cond) {
a.bar(); }
}
void differentBranchesTest(int i) {
{
A a;
if (i > 0) { A b;
b = std::move(a);
} else {
a.foo(); }
}
{
A a, b;
i > 0 ? (void)(b = std::move(a)) : a.bar(); }
{
A a;
a.foo() > 0 ? a.foo() : A(std::move(a)).foo();
#ifdef DFS
#else
#endif
}
{
A a, b;
switch (i) { case 1:
b = std::move(a); break; case 2:
a.foo(); break;
}
}
{
A a, b;
switch (i) { case 1:
b = std::move(a); case 2:
a.foo(); break;
}
}
}
void tempTest() {
A a = A::get();
A::get().foo(); for (int i = 0; i < bignum(); i++) {
A::get().foo(); }
}
void interFunTest1(A &a) {
a.bar(); }
void interFunTest2() {
A a;
A b;
b = std::move(a); interFunTest1(a); }
void foobar(A a, int i);
void foobar(int i, A a);
void paramEvaluateOrderTest() {
A a;
foobar(std::move(a), a.getI());
foobar(a.getI(), std::move(a)); }
void not_known_pass_by_ref(A &a);
void not_known_pass_by_const_ref(const A &a);
void not_known_pass_by_rvalue_ref(A &&a);
void not_known_pass_by_ptr(A *a);
void not_known_pass_by_const_ptr(const A *a);
void regionAndPointerEscapeTest() {
{
A a;
A b;
b = std::move(a);
not_known_pass_by_ref(a);
a.foo(); }
{
A a;
A b;
b = std::move(a); not_known_pass_by_const_ref(a);
a.foo(); }
{
A a;
A b;
b = std::move(a);
not_known_pass_by_rvalue_ref(std::move(a));
a.foo(); }
{
A a;
A b;
b = std::move(a);
not_known_pass_by_ptr(&a);
a.foo(); }
{
A a;
A b;
b = std::move(a); not_known_pass_by_const_ptr(&a);
a.foo(); }
}
void declarationSequenceTest() {
{
A a;
A a1 = a, a2 = std::move(a); }
{
A a;
A a1 = std::move(a), a2 = a; }
}
void logicalOperatorsSequenceTest() {
{
A a;
if (a.foo() > 0 && A(std::move(a)).foo() > 0) { A().bar();
}
}
{
A a;
if (!(a.foo() > 0 && A(std::move(a)).foo() > 0)) { A().bar();
}
}
{
A a;
if (A(std::move(a)).foo() > 0 && a.foo() > 0) { A().bar();
}
}
{
A a;
if (a.foo() > 0 || A(std::move(a)).foo() > 0) { A().bar();
}
}
{
A a;
if (A(std::move(a)).foo() > 0 || a.foo() > 0) { A().bar();
}
}
}
void forRangeSequencesTest() {
A v[2] = {A(), A()};
for (A &a : v) {
A b;
b = std::move(a); }
}
void ifStmtSequencesDeclAndConditionTest() {
for (int i = 0; i < 3; ++i) {
if (A a = A()) {
A b;
b = std::move(a); }
}
}
struct C : public A {
[[clang::reinitializes]] void reinit();
};
void subRegionMoveTest() {
{
A a;
B b = std::move(a.b); a.b.foo(); }
{
A a;
A a1 = std::move(a); a.b.foo(); }
{
A a;
A a1 = std::move(a); a.foo(); a.b.foo(); }
{
C c;
C c1 = std::move(c); c.foo(); c.b.foo(); }
}
void resetSuperClass() {
C c;
C c1 = std::move(c);
c.clear();
C c2 = c; }
void resetSuperClass2() {
C c;
C c1 = std::move(c);
c.reinit();
C c2 = c; }
void reportSuperClass() {
C c;
C c1 = std::move(c); c.foo(); C c2 = c; }
struct Empty {};
Empty inlinedCall() {
Empty e{};
return e; }
void checkInlinedCallZombies() {
while (true)
inlinedCall();
}
void checkLoopZombies() {
while (true) {
Empty e{};
Empty f = std::move(e); }
}
void checkMoreLoopZombies1(bool flag) {
while (flag) {
Empty e{};
if (true)
e; Empty f = std::move(e); }
}
bool coin();
void checkMoreLoopZombies2(bool flag) {
while (flag) {
Empty e{};
while (coin())
e; Empty f = std::move(e); }
}
void checkMoreLoopZombies3(bool flag) {
while (flag) {
Empty e{};
do
e; while (coin());
Empty f = std::move(e); }
}
void checkMoreLoopZombies4(bool flag) {
while (flag) {
Empty e{};
for (; coin();)
e; Empty f = std::move(e); }
}
struct MoveOnlyWithDestructor {
MoveOnlyWithDestructor();
~MoveOnlyWithDestructor();
MoveOnlyWithDestructor(const MoveOnlyWithDestructor &m) = delete;
MoveOnlyWithDestructor(MoveOnlyWithDestructor &&m);
};
MoveOnlyWithDestructor foo() {
MoveOnlyWithDestructor m;
return m;
}
class HasSTLField {
std::vector<int> V;
void testVector() {
std::vector<int> W = std::move(V); V.push_back(123); }
std::unique_ptr<int> P;
void testUniquePtr() {
std::unique_ptr<int> Q = std::move(P); P.get();
*P += 1;
clang_analyzer_warnIfReached(); }
};
void localRValueMove(A &&a) {
A b = std::move(a); a.foo(); }
void localUniquePtr(std::unique_ptr<int> P) {
std::unique_ptr<int> Q = std::move(P); P.get(); }
void localUniquePtrWithArrow(std::unique_ptr<A> P) {
std::unique_ptr<A> Q = std::move(P); P->foo(); }
void getAfterMove(std::unique_ptr<A> P) {
std::unique_ptr<A> Q = std::move(P);
if (P) clang_analyzer_warnIfReached();
A *a = P.get();
a->foo();
}
struct OtherMoveSafeClasses {
std::packaged_task<int(void)> Task;
void test() {
std::packaged_task<int(void)> Task2 = std::move(Task);
std::packaged_task<int(void)> Task3 = std::move(Task);
}
};