-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ctest: add tests for size and alignment of structs, unions, and aliases, and signededness of aliases. #4556
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
base: main
Are you sure you want to change the base?
Conversation
Not sure what the CI error is, doesn't seem to be related to the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few small things but this looks pretty good
ctest-next/templates/test.c
Outdated
uint32_t ctest_signededness_of__{{ alias.id }}(void) { | ||
return ((({{ alias.c_ty }}) -1) < 0); | ||
} | ||
{%- endfor +%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing a trailing newline.
Does your editor have an option to insert this by default? E.g. vscode has files.insertFinalNewline
ctest-next/templates/test.c
Outdated
// Return `1` if the type is signed, otherwise return `0`. | ||
// Casting -1 to the aliased type if signed evaluates to `-1 < 0`, if unsigned to `MAX_VALUE < 0` | ||
uint32_t ctest_signededness_of__{{ alias.id }}(void) { | ||
return ((({{ alias.c_ty }}) -1) < 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a bit easier to read
return ((({{ alias.c_ty }}) -1) < 0); | |
{ alias.c_ty } all_ones = -1; | |
return all_ones < 0; |
ctest-next/src/translator.rs
Outdated
"char" | "short" | "int" | "long" | "long long" | "int8_t" | "int16_t" | ||
| "int32_t" | "int64_t" | "uint8_t" | "uint16_t" | "uint32_t" | "uint64_t" | ||
| "size_t" | "ssize_t" => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just add an arm s.starts_with("int") || s.starts_with("uint")
ctest-next/src/template.rs
Outdated
helper: &TranslateHelper, | ||
) -> Result<(), TranslationError> { | ||
for alias in helper.ffi_items.aliases() { | ||
// && skip_signededness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// && skip_signededness |
ctest-next/src/template.rs
Outdated
if helper.translator.is_signed(helper.ffi_items, &alias.ty) | ||
&& !should_skip_signededness_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early continue to unnest a level
if helper.translator.is_signed(helper.ffi_items, &alias.ty) | |
&& !should_skip_signededness_test | |
if !helper.translator.is_signed(helper.ffi_items, &alias.ty) || should_skip_signededness_test { | |
continue; | |
} |
2e05afe
to
5ced981
Compare
…es, and signededness of aliases.
5ced981
to
48031a5
Compare
Description
This PR adds tests for verifying size and alignment of struct, union, and typedef types, as well as signededness of alias types (if they are signed).
Sources
Checklist
libc-test/semver
have been updated*LAST
or*MAX
areincluded (see #3131)
cd libc-test && cargo test --target mytarget
);especially relevant for platforms that may not be checked in CI