From e374c7fbde3b3a5148b6e8fc302277b6e786965e Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Sat, 2 Feb 2019 00:36:42 -0800 Subject: [PATCH] Fix corner case in stripConstantEndpoints (#2824) `stripConstantEndpoints()` was returning `true` when the first argument was a list only containing an empty string, which could lead to rewrite loops. This commit checks for that case and adds a unit test for it. --- src/theory/strings/theory_strings_rewriter.cpp | 6 ++++++ .../unit/theory/theory_strings_rewriter_white.h | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/theory/strings/theory_strings_rewriter.cpp b/src/theory/strings/theory_strings_rewriter.cpp index 0c8d6ac8d..f90d5bcfd 100644 --- a/src/theory/strings/theory_strings_rewriter.cpp +++ b/src/theory/strings/theory_strings_rewriter.cpp @@ -3583,6 +3583,12 @@ bool TheoryStringsRewriter::stripConstantEndpoints(std::vector& n1, unsigned index1 = r == 0 ? 0 : n2.size() - 1; bool removeComponent = false; Node n1cmp = n1[index0]; + + if (n1cmp.isConst() && n1cmp.getConst().size() == 0) + { + return false; + } + std::vector sss; std::vector sls; n1cmp = decomposeSubstrChain(n1cmp, sss, sls); diff --git a/test/unit/theory/theory_strings_rewriter_white.h b/test/unit/theory/theory_strings_rewriter_white.h index 5f08ce741..bbaa4733f 100644 --- a/test/unit/theory/theory_strings_rewriter_white.h +++ b/test/unit/theory/theory_strings_rewriter_white.h @@ -1180,6 +1180,23 @@ class TheoryStringsRewriterWhite : public CxxTest::TestSuite } } + void testStripConstantEndpoints() + { + Node empty = d_nm->mkConst(::CVC4::String("")); + Node a = d_nm->mkConst(::CVC4::String("A")); + + { + // stripConstantEndpoints({ "" }, { "a" }, {}, {}, 0) ---> false + std::vector n1 = {empty}; + std::vector n2 = {a}; + std::vector nb; + std::vector ne; + bool res = + TheoryStringsRewriter::stripConstantEndpoints(n1, n2, nb, ne, 0); + TS_ASSERT(!res); + } + } + private: ExprManager* d_em; SmtEngine* d_smt; -- 2.30.2