Repository navigation
codegen: Don't add a const to the pointee of const pointers in static wrappers - #3543
Open
thelastbackspace wants to merge 1 commit into
Open
thelastbackspace wants to merge 1 commit into
thelastbackspace wants to merge 1 commit into
Conversation
… wrappers A `T *const` parameter is represented as a const ResolvedTypeRef wrapping a const pointer. The wrapper wrote its own "const " prefix and then the pointer wrote "*const", so the C wrapper ended up taking `const T *const` (and `const const T *const` when the pointee was also const). Fixes rust-lang#3251
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
--wrap-static-fns, a parameter likeuint32_t *const pwas emitted in the C wrapper asconst uint32_t *const p, so the wrapper took a pointer-to-const and passing it to the original function triggered-Wdiscarded-qualifiers. If the pointee was already const (const int *const p) it got worse and producedconst const int *const p.The parameter type is a const
ResolvedTypeRefwrapping a pointer that is itself const. InCSerialize for TypetheResolvedTypeRefarm wrote aconstprefix and then serialized the pointer, which wrote its own*const. The fix only writes the prefix when the referenced type isn't already const, so the qualifier is emitted once and in the right place. Non-pointer cases likeconst uint32_t xorconst enum foo fstill get the prefix, since their wrapped type isn't const.Testing:
takes_const_ptr(int *const arg, const int *const carg)totests/headers/wrap-static-fns.hand updated the generated.cexpectations (both the default and aarch64-linux ones) plus the.rsexpectation. Without the changetest_wrap_static_fnsfails on that line.cargo test -p bindgen-tests(643 passed),cd bindgen-integration && cargo test,cargo +nightly fmt --check,cargo clippy -p bindgen --all-targets.Fixes #3251