Skip to content

add index type to the array type #7140

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 1 commit into from
Sep 19, 2022
Merged

add index type to the array type #7140

merged 1 commit into from
Sep 19, 2022

Conversation

kroening
Copy link
Member

This commit addresses a gap between the arrays of the C programming language and standard array theories. In C, array indices are subject to arithmetic promotion, and thus, may have a variety of types, depending on the operand type. Standard array theories expect one specific index type per array type.

The C front-end now annotates the array type with that index type. We will eventually enforce that all index expressions use this type.

  • 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).
  • 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.

@codecov
Copy link

codecov bot commented Sep 18, 2022

Codecov Report

Merging #7140 (80f9834) into develop (f20515f) will increase coverage by 0.00%.
The diff coverage is 95.65%.

@@           Coverage Diff            @@
##           develop    #7140   +/-   ##
========================================
  Coverage    77.86%   77.87%           
========================================
  Files         1576     1576           
  Lines       181805   181812    +7     
========================================
+ Hits        141571   141578    +7     
  Misses       40234    40234           
Impacted Files Coverage Δ
src/ansi-c/c_typecheck_expr.cpp 74.17% <ø> (ø)
src/goto-instrument/interrupt.cpp 0.00% <ø> (ø)
src/jsil/jsil_entry_point.cpp 0.00% <0.00%> (ø)
src/util/pointer_expr.h 80.83% <ø> (ø)
src/ansi-c/ansi_c_entry_point.cpp 89.45% <100.00%> (ø)
src/ansi-c/c_typecheck_base.cpp 82.50% <100.00%> (ø)
src/ansi-c/c_typecheck_type.cpp 77.19% <100.00%> (+0.02%) ⬆️
src/solvers/smt2/smt2_conv.cpp 68.69% <100.00%> (ø)
src/util/std_types.cpp 87.36% <100.00%> (+0.55%) ⬆️
src/util/std_types.h 95.79% <100.00%> (+0.02%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

out << "(Array ";
convert_type(array_type.size().type());
convert_type(array_type.index_type());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wasn't .size().type() correct here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It only works when the array has a size.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What information does SMT-LIB require at this point? Agreed that not all arrays have a size, which may be a problem, but I'm just not sufficiently knowledgable in SMT-LIB to tell whether this change really makes sense. If that's just a workaround for a missing size then I remain unconvinced this is the right change to make.

Copy link
Member Author

Choose a reason for hiding this comment

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

SMT-LIB does require the index type; arrays are maps from indices to the codomain type. Using the type of the size was a workaround.

This commit addresses a gap between the arrays of the C programming language
and standard array theories.  In C, array indices are subject to arithmetic
promotion, and thus, may have a variety of types, depending on the operand
type.  Standard array theories expect one specific index type per array
type.

The C front-end now annotates the array type with that index type.  We will
eventually enforce that all index expressions use this type.
@kroening kroening merged commit 29d432c into develop Sep 19, 2022
@kroening kroening deleted the array_index_type branch September 19, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants