diff options
Diffstat (limited to 'unittests/Ref')
-rw-r--r-- | unittests/Ref/Makefile | 19 | ||||
-rw-r--r-- | unittests/Ref/RefTest.cpp | 31 |
2 files changed, 50 insertions, 0 deletions
diff --git a/unittests/Ref/Makefile b/unittests/Ref/Makefile new file mode 100644 index 00000000..3117a5fd --- /dev/null +++ b/unittests/Ref/Makefile @@ -0,0 +1,19 @@ +##===- unittests/Expr/Makefile -----------------------------*- Makefile -*-===## + +LEVEL := ../.. +include $(LEVEL)/Makefile.config + +TESTNAME := RefTest +STP_LIBS := stp_c_interface.a stp_AST.a stp_bitvec.a \ + stp_constantbv.a stp_sat.a stp_simplifier.a +USEDLIBS := kleaverExpr.a kleeBasic.a +ifeq ($(ENABLE_EXT_STP),0) + USEDLIBS += $(STP_LIBS) +endif +LINK_COMPONENTS := support + +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest + +ifeq ($(ENABLE_EXT_STP),1) + LIBS += -lstp +endif diff --git a/unittests/Ref/RefTest.cpp b/unittests/Ref/RefTest.cpp new file mode 100644 index 00000000..229fd9a8 --- /dev/null +++ b/unittests/Ref/RefTest.cpp @@ -0,0 +1,31 @@ +/* Regression test for a bug caused by assigning a ref to itself. + More details at http://keeda.stanford.edu/pipermail/klee-commits/2012-February/000904.html */ + +#include "gtest/gtest.h" +#include <iostream> +#include "klee/util/Ref.h" +using klee::ref; + +int finished = 0; + +struct Expr +{ + int refCount; + Expr() : refCount(0) { + //std::cout << "Expr(" << this << ") created\n"; + } + ~Expr() { + //std::cout << "Expr(" << this << ") destroyed\n"; + EXPECT_EQ(finished, 1); + } +}; + +TEST(RefTest, SelfAssign) +{ + struct Expr *r_e = new Expr(); + ref<Expr> r(r_e); + EXPECT_EQ(r_e->refCount, 1); + r = r; + EXPECT_EQ(r_e->refCount, 1); + finished = 1; +} |