diff options
author | Lukas Wölfer <lukas.woelfer@rwth-aachen.de> | 2018-08-04 23:14:50 +0200 |
---|---|---|
committer | Cristian Cadar <c.cadar@imperial.ac.uk> | 2019-03-17 15:43:21 +0000 |
commit | 7ad366f363d23b0aea788fca69349e50180f5f78 (patch) | |
tree | b24cee8cae488fc841d2e1ebfcaba069779b1f87 /test | |
parent | 3b6f5e52d0cec5e8018c590c9feccb39bb03206c (diff) | |
download | klee-7ad366f363d23b0aea788fca69349e50180f5f78.tar.gz |
Added libcxx flag
Diffstat (limited to 'test')
-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 | ||||
-rw-r--r-- | test/lit.cfg | 3 | ||||
-rw-r--r-- | test/lit.site.cfg.in | 2 |
8 files changed, 120 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); +} diff --git a/test/lit.cfg b/test/lit.cfg index 7c5ed220..1dafa911 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -155,6 +155,9 @@ config.substitutions.append( ('%gentmp', os.path.join(klee_src_root, 'scripts/genTempFiles.sh')) ) +config.substitutions.append( + ('%libcxx_include', getattr(config, 'libcxx_include_dir', None))) + # Add feature for the LLVM version in use, so it can be tested in REQUIRES and # XFAIL checks. We also add "not-XXX" variants, for the same reason. known_llvm_versions = set(["3.4", "3.5", "3.6", "3.7", "3.8", "3.9"]) diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index 7839b66e..e0827559 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -9,6 +9,8 @@ config.klee_obj_root = "@KLEE_BINARY_DIR@" config.klee_tools_dir = "@KLEE_TOOLS_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.libcxx_include_dir = "@KLEE_LIBCXX_INCLUDE_DIR@" + # Needed to check if a hack needs to be applied config.llvm_version_major = "@LLVM_VERSION_MAJOR@" config.llvm_version_minor = "@LLVM_VERSION_MINOR@" |