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

Adding offsetof checks as static assertions when refining a C type #144

Merged
merged 5 commits into from
Aug 23, 2024

Conversation

nikswamy
Copy link
Contributor

Cf. Issue #143

then false
else let suffix' = String.sub s (l - sl) sl in
suffix = suffix'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to Utils

offsets |>
List.collect
(fun offset ->
if TypeSizes.is_alignment_field (fst offset)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exclude assertions on fields that are added for alignment padding; they are implicit in the C type

let ds = List.map (decl_size_with_alignment env) ds in
let ge = B.global_env_of_env (fst env) in
ds |> List.iter (fun d ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update the global environment with revised type declarations after fields (may) have been added for alignment padding

#ifndef C_ASSERT
#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
#endif
typedef char CIRCLE[20];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revise the test case, since we now also check offsets, not just sizes

@tahina-pro tahina-pro merged commit fa2690c into master Aug 23, 2024
6 checks passed
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