Skip to content

util: expose is_zero_width via util/pointer_offset_size#9016

Open
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:is_zero_width
Open

util: expose is_zero_width via util/pointer_offset_size#9016
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:is_zero_width

Conversation

@tautschnig
Copy link
Copy Markdown
Collaborator

is_zero_width(const typet &, const namespacet &) was a file-static helper in src/solvers/smt2/smt2_conv.cpp. The predicate is generic ('does this type have effective width of zero bits?') and not specific to the non-incremental SMT2 backend; the incremental SMT2 backend will need exactly the same predicate to detect empty-typed expressions correctly without re-treading the same struct/union/ struct-tag/union-tag/array recursion. Move the function to src/util/pointer_offset_size.{h,cpp} alongside its semantic neighbours pointer_offset_size and pointer_offset_bits, drop the 'static' qualifier on the original definition, and remove the duplicate body from smt2_conv.cpp.

No functional change. smt2_conv.cpp continues to call is_zero_width through the shared header (which it already includes); other back-ends and util-level call sites can now do the same.

  • Each commit message has a non-empty body, explaining why the change was made.
  • 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.

@tautschnig tautschnig self-assigned this May 27, 2026
Copilot AI review requested due to automatic review settings May 27, 2026 17:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.60%. Comparing base (01ebe42) to head (41dbde1).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #9016   +/-   ##
========================================
  Coverage    80.59%   80.60%           
========================================
  Files         1711     1711           
  Lines       189454   189491   +37     
  Branches        73       73           
========================================
+ Hits        152697   152736   +39     
+ Misses       36757    36755    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

is_zero_width(const typet &, const namespacet &) was a file-static
helper in src/solvers/smt2/smt2_conv.cpp. The predicate is generic
('does this type have effective width of zero bits?') and not
specific to the non-incremental SMT2 backend; the incremental SMT2
backend will need exactly the same predicate to detect empty-typed
expressions correctly without re-treading the same struct/union/
struct-tag/union-tag/array recursion. Move the function to
src/util/pointer_offset_size.{h,cpp} alongside its semantic
neighbours pointer_offset_size and pointer_offset_bits, drop the
'static' qualifier on the original definition, and remove the
duplicate body from smt2_conv.cpp.

smt2_conv.cpp continues to call is_zero_width through the shared
header (which it already includes); other back-ends and util-level
call sites can now do the same.

Behaviour change: the predicate now also unwraps ID_c_enum_tag via
ns.follow_tag() and recurses into the underlying integer type of
ID_c_enum (via c_enum_typet::subtype()). The previous code unwrapped
ID_struct_tag and ID_union_tag but fell through to 'return false'
for ID_c_enum_tag — which gave the correct answer for every C enum
that exists in practice (whose underlying integer type has non-zero
width) but was an unprincipled coincidence rather than the predicate
behaving symmetrically across all tag kinds. The new arms make the
symmetry explicit: a hypothetical zero-width c_enum (e.g. one whose
underlying type is empty_typet) now correctly reports as zero-width,
matching the existing struct/union behaviour.

A focused unit test in unit/util/pointer_offset_size.cpp pins down
the contract: empty_typet, signed/zero-width bitvectors, struct with
all-empty / mixed components, array of empty type with constant and
symbolic size (the deliberately non-obvious branch), struct_tag_typet
resolving to an empty struct, and the new c_enum / c_enum_tag arms
including both the regular signed-int-underlying case and the
zero-width-underlying edge case.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
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.

2 participants