From: Gereon Kremer Date: Wed, 19 Aug 2020 16:54:17 +0000 (+0200) Subject: Changes assertion (about maximum set cardinality) to an exception. (#4907) X-Git-Tag: cvc5-1.0.0~2979 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1c67e4cc188b4812cedb614e6e998ea944ddb320;p=cvc5.git Changes assertion (about maximum set cardinality) to an exception. (#4907) Changes the assertion that checks for the maximum cardinality of set models to an exception, following #4374. Also cleans up the code around it: previously, the Rational was checked against LONG_MAX, converted to std::uint32_t and then stored into an unsigned. Now we use std::uint32_t all the way. Fixes #4374. --- diff --git a/src/theory/sets/cardinality_extension.cpp b/src/theory/sets/cardinality_extension.cpp index 1c12c71e4..4aa866d27 100644 --- a/src/theory/sets/cardinality_extension.cpp +++ b/src/theory/sets/cardinality_extension.cpp @@ -997,9 +997,14 @@ void CardinalityExtension::mkModelValueElementsFor( Node v = val.getModelValue(it->second); Trace("sets-model") << "Cardinality of " << eqc << " is " << v << std::endl; - Assert(v.getConst() <= LONG_MAX) - << "Exceeded LONG_MAX in sets model"; - unsigned vu = v.getConst().getNumerator().toUnsignedInt(); + if (v.getConst() > UINT32_MAX) + { + std::stringstream ss; + ss << "The model for " << eqc << " was computed to have cardinality " + << v << ". We only allow sets up to cardinality " << UINT32_MAX; + throw LogicException(ss.str()); + } + std::uint32_t vu = v.getConst().getNumerator().toUnsignedInt(); Assert(els.size() <= vu); NodeManager* nm = NodeManager::currentNM(); if (elementType.isInterpretedFinite()) diff --git a/src/theory/strings/theory_strings.cpp b/src/theory/strings/theory_strings.cpp index b23765313..c78e8dc2a 100644 --- a/src/theory/strings/theory_strings.cpp +++ b/src/theory/strings/theory_strings.cpp @@ -312,7 +312,7 @@ bool TheoryStrings::collectModelInfoType( std::map< Node, Node > processed; //step 1 : get all values for known lengths std::vector< Node > lts_values; - std::map values_used; + std::map values_used; std::vector len_splits; for( unsigned i=0; i() > Rational(String::maxSize())) + if (len_value.getConst() > String::maxSize()) { std::stringstream ss; - ss << "Cannot generate model with string whose length exceeds UINT32_MAX"; + ss << "The model was computed to have strings of length " << len_value + << ". We only allow strings up to length " << String::maxSize(); throw LogicException(ss.str()); } - unsigned lvalue = + std::size_t lvalue = len_value.getConst().getNumerator().toUnsignedInt(); - std::map::iterator itvu = values_used.find(lvalue); + auto itvu = values_used.find(lvalue); if (itvu == values_used.end()) { values_used[lvalue] = lts[i]; @@ -417,7 +418,7 @@ bool TheoryStrings::collectModelInfoType( if( !pure_eq.empty() ){ if( lts_values[i].isNull() ){ // start with length two (other lengths have special precendence) - unsigned lvalue = 2; + std::size_t lvalue = 2; while( values_used.find( lvalue )!=values_used.end() ){ lvalue++; } diff --git a/test/regress/regress0/strings/large-model.smt2 b/test/regress/regress0/strings/large-model.smt2 index 74b781c82..f3aa7f8f2 100644 --- a/test/regress/regress0/strings/large-model.smt2 +++ b/test/regress/regress0/strings/large-model.smt2 @@ -1,5 +1,6 @@ ; COMMAND-LINE: --lang=smt2.6 --check-models -; EXPECT: (error "Cannot generate model with string whose length exceeds UINT32_MAX") +; SCRUBBER: sed -E 's/of length [0-9]+/of length LENGTH/' +; EXPECT: (error "The model was computed to have strings of length LENGTH. We only allow strings up to length 4294967295") ; EXIT: 1 (set-logic SLIA) (declare-fun x () String)