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

Dimensions of multi-dimensional arrays must have consistent checked properties #32

Closed
secure-sw-dev-bot opened this issue Jan 16, 2022 · 2 comments

Comments

@secure-sw-dev-bot
Copy link

This issue was copied from checkedc/checkedc-clang#32


The implementation of Checked C in clang allows dimensions of multi-dimensional arrays to have different checked properties. A dimension could be declared as unchecked by prefixing it with the unchecked keyword. The Checked C specification says all dimensions of multi-dimensional arrays have to either be all checked or all unchecked. We thought about changing the spec, but have decided to stick with it because allowing dimensions to have different checked properties is confusing.

This changes removes the ability to use the `unchecked' keyword to declare unchecked dimensions for multi-dimensional arrays (addressing GitHub issue #27). In addition, it adds error checking that dimensions in a multi-dimensional array are either all checked or unchecked.

There are some corner cases to handle due to typedefs. In C, an array is an array of arrays. A typedef can define an array type that is used as a nested array type. The case where the enclosing array and the nested array differ in their checked property because of a typedef is now an error. We take some care to generate an error message that explains what is going on.

In addition, we also have to handle parenthesized types. The checked property for a multi-dimensional array propagates from the outer array type to inner array types declared as part of the a declaration (int a checked[10][10] declares a checked array of checked arrays). Testing for this change uncovered that the checked property was not being propagating properly to nested types when a declarator was parenthesized (int (a checked[10])[10]). This change fixes that.

Testing:

  • Wrote new feature tests for testing that array dimensions have consistent checked properties. This changes will be checked in separately to the Checked C repo in typechecking\checked_arrays.c.
  • Wrote new feature tests for testing parenthesized array declarators for checked arrays.
  • Code still passes the existing clang baseline tests.
@secure-sw-dev-bot
Copy link
Author

Comment from @msftclas:

Hi @dtarditi, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (David Tarditi). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@secure-sw-dev-bot
Copy link
Author

Comment from @reubeno:

Apart from my one comment, looks good to me.

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