Skip to content

goto-symex: decide more pointer comparisons from value sets - #9633

Draft
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/symex-pointer-comparison-value-sets
Draft

tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/symex-pointer-comparison-value-sets

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

try_evaluate_pointer_comparison decides p == q, for a pointer symbol p, from p's value set when q is an address. It gave up in two cases that are common with arrays:

  • q was the address of an array element other than the first: the simplifier writes &a[i] as &a[0] + i, which is not an address_of expression. Pointer arithmetic with constants on an address is now accepted.
  • An entry of p's value set had an unknown offset. Value sets keep one offset per object, so a pointer that is one of two elements of an array has an unknown offset. Whatever that offset, a pointer into another object than q's (or than NULL) cannot equal q: pointer arithmetic only changes the offset part of a pointer.

For example, a pointer that is one of &fp[0] and &fp[1] compared with &bp[0], &bp[1] or NULL: symbolic execution kept all three branches and now prunes them (regression/cbmc/pointer-comparison-value-set, unit tests). Comparisons with addresses in the same object as an entry with unknown offset (here &fp[2]) are still left to the solver.

Measurements (one run at a time):

  • A pointer that is one of two elements of an array, compared with each of 64 elements of another array and of its own, each branch calling a small function: 6557 -> 3485 steps, 1.68 s -> 0.83 s.
  • scripts/profile_cbmc.py --auto-large --runs 3: the same steps on all ten benchmarks; the pre-solver times of the two builds differed by -28 % to +68 % across runs in both orders on a host shared with other jobs (load 7 to 23), i.e. no difference is measurable there.

regression/cbmc/pointer-comparison-value-set/test.desc fails on develop. regression/cbmc (also with --paths lifo), cbmc-concurrency, cbmc-cpp, cbmc-cover, cbmc-shadow-memory and cbmc-primitives pass with --validate-goto-model --validate-ssa-equation; cbmc-library's mmap/test, mmap/test_02 and munmap/test fail with these options, as on develop.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

try_evaluate_pointer_comparison decides `p == q`, for a pointer symbol p,
from p's value set when q is an address. It gave up in two cases that
are common with arrays:

- q was the address of an array element other than the first: the
  simplifier writes &a[i] as &a[0] + i, which is not an address_of
  expression. Pointer arithmetic with constants on an address is now
  accepted.
- An entry of p's value set had an unknown offset. Value sets keep one
  offset per object, so a pointer that is one of two elements of an
  array has an unknown offset. Whatever that offset, a pointer into
  another object than q's (or than NULL) cannot equal q: pointer
  arithmetic only changes the offset part of a pointer.

For example, a pointer that is one of &fp[0] and &fp[1] compared with
&bp[0], &bp[1] or NULL: symbolic execution kept all three branches and
now prunes them (regression/cbmc/pointer-comparison-value-set, unit
tests). Comparisons with addresses in the same object as an entry with
unknown offset (here &fp[2]) are still left to the solver.

Measurements (one run at a time):
- A pointer that is one of two elements of an array, compared with each
  of 64 elements of another array and of its own, each branch calling a
  small function: 6557 -> 3485 steps, 1.68 s -> 0.83 s.
- scripts/profile_cbmc.py --auto-large --runs 3: the same steps on all
  ten benchmarks; the pre-solver times of the two builds differed by
  -28 % to +68 % across runs in both orders on a host shared with other
  jobs (load 7 to 23), i.e. no difference is measurable there.

regression/cbmc/pointer-comparison-value-set/test.desc fails on develop.
regression/cbmc (also with --paths lifo), cbmc-concurrency, cbmc-cpp,
cbmc-cover, cbmc-shadow-memory and cbmc-primitives pass with
--validate-goto-model --validate-ssa-equation; cbmc-library's mmap/test,
mmap/test_02 and munmap/test fail with these options, as on develop.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant