Skip to content
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

Handle slicing operation with non-unit step length and indeterminant upper bound in ExprWrapper #1065

Open
Raine-Yang-UofT opened this issue Jul 15, 2024 · 0 comments

Comments

@Raine-Yang-UofT
Copy link
Contributor

Raine-Yang-UofT commented Jul 15, 2024

Currently, the parse_index_op method in ExprWrapper does not properly handle cases where a string slicing operation has a step length greater than 1 and the ending index is the end of the string. For example, x[1::2].

Since z3.SubString does not support a "step length" argument, the current approach converts a slicing with step into a list of SubString connected with z3.Concat. This method fails when we have an unknown upper bound.

As shown in the code below, the current approach handles this case by raising a Z3ParseError and skipping the parsing for this expression. An alternative algorithm may be required to cover all slicing operations correctly.

# in `parse_index_op`

if step == 1:
    return z3.SubString(value, lower, upper - lower)

# unhandled case: the upper bound is indeterminant
if step != 1 and upper == z3.Length(value):
    raise Z3ParseException(
         "Unable to convert a slicing operation with a non-unit step length and an indeterminant upper bound"
    )

return z3.Concat(*(z3.SubString(value, i, 1) for i in range(lower, upper, step)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant