-
Notifications
You must be signed in to change notification settings - Fork 273
Move exprt::bounded_size to complexity_limitert #5988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,30 +24,6 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <stack> | ||
|
||
/// Returns the size of the exprt added to count without searching significantly | ||
/// beyond the supplied limit. | ||
std::size_t exprt::bounded_size(std::size_t count, std::size_t limit) const | ||
{ | ||
const auto &ops = operands(); | ||
count += ops.size(); | ||
for(const auto &op : ops) | ||
{ | ||
if(count >= limit) | ||
{ | ||
return count; | ||
} | ||
count = op.bounded_size(count, limit); | ||
} | ||
return count; | ||
} | ||
|
||
/// Returns the size of the exprt without significantly searching beyond the | ||
/// supplied limit. | ||
std::size_t exprt::bounded_size(std::size_t limit) const | ||
{ | ||
return bounded_size(1, limit); | ||
} | ||
|
||
/// Return whether the expression is a constant. | ||
/// \return True if is a constant, false otherwise | ||
bool exprt::is_constant() const | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Unit test for goto-symex/complexity_limiter | ||
|
||
Author: Diffblue Ltd | ||
|
||
\*******************************************************************/ | ||
|
||
#include <testing-utils/use_catch.h> | ||
|
||
#include <util/arith_tools.h> | ||
|
||
#include <goto-symex/complexity_limiter.h> | ||
|
||
TEST_CASE( | ||
"Bounded expression size is computed correctly", | ||
"[core][goto-symex][complexity_limiter]") | ||
{ | ||
// Helper types and functions for constructing test expressions. | ||
const typet type = signedbv_typet(32); | ||
std::function<exprt(size_t)> make_expression; | ||
make_expression = [&](size_t size) -> exprt { | ||
PRECONDITION(size != 0); | ||
if(size <= 1) | ||
return from_integer(1, type); | ||
if(size == 2) | ||
return unary_minus_exprt(from_integer(1, type)); | ||
return plus_exprt(from_integer(1, type), make_expression(size - 2)); | ||
}; | ||
// Actual test cases. | ||
REQUIRE(complexity_limitert::bounded_expr_size(make_expression(1), 10) == 1); | ||
REQUIRE(complexity_limitert::bounded_expr_size(make_expression(2), 10) == 2); | ||
REQUIRE(complexity_limitert::bounded_expr_size(make_expression(3), 10) == 3); | ||
|
||
REQUIRE(complexity_limitert::bounded_expr_size(make_expression(30), 10) < 13); | ||
REQUIRE( | ||
complexity_limitert::bounded_expr_size(make_expression(30), 10) >= 10); | ||
} | ||
|
||
TEST_CASE( | ||
"Bounded expression size versus pathological example", | ||
"[core][goto-symex][complexity_limiter]") | ||
{ | ||
const typet type = signedbv_typet(32); | ||
exprt pathology = plus_exprt(from_integer(1, type), from_integer(1, type)); | ||
// Create an infinite exprt by self reference! | ||
pathology.add_to_operands(pathology); | ||
// If bounded expression size is not checking the bound this will never | ||
// terminate. | ||
REQUIRE(complexity_limitert::bounded_expr_size(pathology, 10) < 13); | ||
REQUIRE(complexity_limitert::bounded_expr_size(pathology, 10) >= 10); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we aren't going to fix this, can we at least have a comment saying this is potentially risky?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment now added to the public member function.