diff options
Diffstat (limited to 'test/CXX')
-rw-r--r-- | test/CXX/symex/libc++/atexit.cpp | 15 | ||||
-rw-r--r-- | test/CXX/symex/libc++/compile_with_libcxx.sh | 15 | ||||
-rw-r--r-- | test/CXX/symex/libc++/cout.cpp | 9 | ||||
-rw-r--r-- | test/CXX/symex/libc++/cout_sym.cpp | 14 | ||||
-rw-r--r-- | test/CXX/symex/libc++/dynamic_cast.cpp | 50 | ||||
-rw-r--r-- | test/CXX/symex/libc++/vector.cpp | 12 |
6 files changed, 115 insertions, 0 deletions
diff --git a/test/CXX/symex/libc++/atexit.cpp b/test/CXX/symex/libc++/atexit.cpp new file mode 100644 index 00000000..3d9e6834 --- /dev/null +++ b/test/CXX/symex/libc++/atexit.cpp @@ -0,0 +1,15 @@ +// RUN: sh %S/compile_with_libcxx.sh "%llvmgxx" "%s" "%S" "%t" "%klee" "%libcxx_include" | FileCheck %s +// +// CHECK: Returning from main +// CHECK: atexit_1 +// CHECK: atexit_2 + +#include <iostream> +#include <cstdlib> + +int main(int argc, char** args){ + auto atexithandler2 = std::atexit([](){std::cout << "atexit_2" << std::endl;}); + auto atexithandler1 = std::atexit([](){std::cout << "atexit_1" << std::endl;}); + std::cout << "Returning from main" << std::endl; + return 0; +} diff --git a/test/CXX/symex/libc++/compile_with_libcxx.sh b/test/CXX/symex/libc++/compile_with_libcxx.sh new file mode 100644 index 00000000..8c45ec62 --- /dev/null +++ b/test/CXX/symex/libc++/compile_with_libcxx.sh @@ -0,0 +1,15 @@ +set -x +set -e +set -o +set -u + +COMPILER=$1 +FILENAME=$2 +CURDIR=$3 +TMPNAME=$4 +KLEE=$5 +INCLUDE_DIR=$6 + +$COMPILER $FILENAME -std=c++11 -I ${INCLUDE_DIR} -emit-llvm -O0 -c -g -nostdinc++ -o ${TMPNAME}.bc +rm -rf ${TMPNAME}.klee-out +$KLEE --output-dir=${TMPNAME}.klee-out --no-output --exit-on-error --libc=uclibc --use-libcxx ${TMPNAME}.bc 2>&1 diff --git a/test/CXX/symex/libc++/cout.cpp b/test/CXX/symex/libc++/cout.cpp new file mode 100644 index 00000000..2539b67f --- /dev/null +++ b/test/CXX/symex/libc++/cout.cpp @@ -0,0 +1,9 @@ +// RUN: sh %S/compile_with_libcxx.sh "%llvmgxx" "%s" "%S" "%t" "%klee" "%libcxx_include" + +#include <iostream> + +int main(int argc, char** args){ + std::cout << "cout" << std::endl; + std::cerr << "cerr" << std::endl; + return 0; +} diff --git a/test/CXX/symex/libc++/cout_sym.cpp b/test/CXX/symex/libc++/cout_sym.cpp new file mode 100644 index 00000000..52e59f05 --- /dev/null +++ b/test/CXX/symex/libc++/cout_sym.cpp @@ -0,0 +1,14 @@ +// RUN: sh %S/compile_with_libcxx.sh "%llvmgxx" "%s" "%S" "%t" "%klee" "%libcxx_include" + +#include <iostream> +#include "klee/klee.h" + +int main(int argc, char** args){ + int x = klee_int("x"); + if (x > 0){ + std::cout << "greater: " << x << std::endl; + } else { + std::cout << "lower: " << x << std::endl; + } + return 0; +} diff --git a/test/CXX/symex/libc++/dynamic_cast.cpp b/test/CXX/symex/libc++/dynamic_cast.cpp new file mode 100644 index 00000000..53e5bc69 --- /dev/null +++ b/test/CXX/symex/libc++/dynamic_cast.cpp @@ -0,0 +1,50 @@ +// RUN: sh %S/compile_with_libcxx.sh "%llvmgxx" "%s" "%S" "%t" "%klee" "%libcxx_include" + +// Copied from 'http://en.cppreference.com/w/cpp/language/dynamic_cast' + +struct V { + virtual void f() {}; // must be polymorphic to use runtime-checked dynamic_cast +}; +struct A : virtual V {}; +struct B : virtual V { + B(V* v, A* a) { + // casts during construction (see the call in the constructor of D below) + dynamic_cast<B*>(v); // well-defined: v of type V*, V base of B, results in B* + dynamic_cast<B*>(a); // undefined behavior: a has type A*, A not a base of B + } +}; +struct D : A, B { + D() : B((A*)this, this) { } +}; + +struct Base { + virtual ~Base() {} +}; + +struct Derived: Base { + virtual void name() {} +}; + +int main() +{ + D d; // the most derived object + A& a = d; // upcast, dynamic_cast may be used, but unnecessary + D& new_d = dynamic_cast<D&>(a); // downcast + B& new_b = dynamic_cast<B&>(a); // sidecast + + + Base* b1 = new Base; + if(Derived* d = dynamic_cast<Derived*>(b1)) + { + d->name(); // safe to call + } + + Base* b2 = new Derived; + if(Derived* d = dynamic_cast<Derived*>(b2)) + { + d->name(); // safe to call + } + + delete b1; + delete b2; +} diff --git a/test/CXX/symex/libc++/vector.cpp b/test/CXX/symex/libc++/vector.cpp new file mode 100644 index 00000000..27f5daba --- /dev/null +++ b/test/CXX/symex/libc++/vector.cpp @@ -0,0 +1,12 @@ +// RUN: sh %S/compile_with_libcxx.sh "%llvmgxx" "%s" "%S" "%t" "%klee" "%libcxx_include" | FileCheck %s + +// CHECK: KLEE: done: completed paths = 1 + +#include "klee/klee.h" +#include <vector> + +int main(int argc, char **args) { + std::vector<int> a; + a.push_back(klee_int("Test")); + return a.at(0); +} |