Skip to content

ctest: check incompatible pointer types for public fields.#5205

Draft
mbyx wants to merge 1 commit into
rust-lang:mainfrom
mbyx:ctest-incompatible-pointer-types
Draft

ctest: check incompatible pointer types for public fields.#5205
mbyx wants to merge 1 commit into
rust-lang:mainfrom
mbyx:ctest-incompatible-pointer-types

Conversation

@mbyx

@mbyx mbyx commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

Attempts to fix #5196 by adding a test for improper field types into the C side of the field_type test.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot rustbot added the ctest Issues relating to the ctest crate label Jun 23, 2026
@mbyx mbyx force-pushed the ctest-incompatible-pointer-types branch from f491d92 to f5532a9 Compare June 23, 2026 16:30
@mbyx

mbyx commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Also, I'm not sure, but I think this was already tested in a way? Because while working on it I got the following result:

cargo:warning=/tmp/.tmpQcOH17/incompatible_ptr_types.out.c:66:9: error: assignment to 'ctest_field_ty__Foo__a' {aka 'float *'} from incompatible pointer type 'int32_t *' {aka 'int *'} [-Werror=incompatible-pointer-types]
cargo:warning=   66 |     ptr = &b->a;
cargo:warning=      |         ^
cargo:warning=/tmp/.tmpQcOH17/incompatible_ptr_types.out.c:69:12: error: returning 'int32_t *' {aka 'int *'} from a function with incompatible return type 'ctest_field_ty__Foo__a' {aka 'float *'} [-Werror=incompatible-pointer-types]
cargo:warning=   69 |     return &b->a;
cargo:warning=      |            ^~~~~
cargo:warning=At top level:

For the specific test case at least, the correct warning would have popped up even if the extra test lines had not been added. I might not be understanding the requirements here though.

Oh and if that is the case, the reason for it not detecting before may be that the field was not public, as non public fields can't be checked. I think, it's been a while since I looked at ctest :)

@mbyx mbyx force-pushed the ctest-incompatible-pointer-types branch from f5532a9 to 4b6d4a9 Compare June 23, 2026 16:34
@tgross35

Copy link
Copy Markdown
Contributor

Huh; I thought I saw a case related to #1020 where we had an integer as a field but a union is the correct type, and no skips. Now I can't find that, and you're right that it seems covered.

Maybe I was looking at union fields - do you know if we test those?

@mbyx

mbyx commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Yup, we do test those. The populate_field_ptr_tests in template.rs creates the field_ptr test for all public struct and union fields that haven't been manually skipped. And the field_ptr test creates a pointer to that field that is returned by the function, while using both the actual and the Rust translated types, so it should catch all instances of this warning.

@tgross35

Copy link
Copy Markdown
Contributor

You're right, sorry for all the confusion here. It looks like tests don't cover this, would you mind adding them? Could just be ctest-test/src/mismatched-union-field-ty.{c,rs} and ctest-test/src/mismatched-struct-field-ty.{c,rs} to make sure compilation fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ctest Issues relating to the ctest crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctest: detect improper field types

3 participants