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

rust_debug: Cast size_t values to unsigned long before printing. #2801

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

CohenArthur
Copy link
Member

@CohenArthur CohenArthur commented Jan 17, 2024

Using %lu to format size_t values breaks 32 bit targets, and %zu is not
supported by one of the hosts GCC aims to support - HPUX

Fixes #2798

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
Cast size_t value to unsigned long.
* expand/rust-proc-macro.cc (load_macros): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.

Using %lu to format size_t values breaks 32 bit targets, and %zu is not
supported by one of the hosts GCC aims to support - HPUX

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
	Cast size_t value to unsigned long.
	* expand/rust-proc-macro.cc (load_macros): Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
@CohenArthur CohenArthur added this pull request to the merge queue Jan 18, 2024
Merged via the queue into Rust-GCC:master with commit 5b40b9c Jan 18, 2024
9 checks passed
@7Z0t99
Copy link

7Z0t99 commented Jan 18, 2024

I see that this was already merged, but I still wonder whether this solution is sound on all platforms, because sizeof(unsigned long) < sizeof(size_t) on some platforms, e.g. on win64.

@CohenArthur
Copy link
Member Author

@7Z0t99 you're right that it is unsound, the correct fix would be to use the PRIu64 format specifier. this is a quick and dirty fix as this breaks the build on some GCC targets. it is unsound in that it would display incorrect length values if we have more than UINT32_MAX proc macros at once for example, which is a much bigger issue and shouldn't happen :) these are debug prints anyway and will probably be removed soon.

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.

Remove use of %lu format specifier for size_t values
3 participants