WIP: Compare type sizes in druntime with ImportC
Types for bindings of C libraries in druntime need to match the C headers. Small differences can result in hard to debug problems.
This test tries to automatically find types with a wrong size. This is done by also getting type sizes from C headers using ImportC and comparing them. Differences between the sizes can have different reasons:
- Bugs in ImportC (e.g. for bitfields) can result in a wrong size
- Type definitions in druntime can be wrong
- Different preprocessor options could be used, like _FILE_OFFSET_BITS
- Size differences can be fine, because some structs contain a member for the size or a version
Members of structs and unions with the same name are also compared. For types with potential problems a comparison of the layout is printed.
Thanks for your pull request and interest in making D better, @tim-dlang! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:
- My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
- My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
- I have provided a detailed rationale explaining my changes
- New or modified functions have Ddoc comments (with
Params:andReturns:)
Please see CONTRIBUTING.md for more information.
If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.
Bugzilla references
Your PR doesn't reference any Bugzilla issue.
If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
Testing this PR locally
If you don't have a local development environment setup, you can use Digger to test this PR:
dub run digger -- build "master + dmd#16571"
Some issues found with this test: ImportC: Bitfield layout wrong for int64 on 32-bit Linux (https://issues.dlang.org/show_bug.cgi?id=24592) ImportC: Packed struct has wrong layout (https://issues.dlang.org/show_bug.cgi?id=24594) Some structs in core.sys.posix.sys.types should be union instead of struct (https://issues.dlang.org/show_bug.cgi?id=24593)
Very cool! :+1:
The test now contains a list of known problems, which are only treated as warnings and not errors. This would allow to merge the test before fixing the problems. New problems would still be found by the test.