public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Fix size used in unsized adjustments Date: Wed, 8 Jun 2022 12:43:28 +0000 (GMT) [thread overview] Message-ID: <20220608124328.2ED5838936CA@sourceware.org> (raw) https://gcc.gnu.org/g:f5bceb679420b999aa63c1b34dd0e0075cf9c5fd commit f5bceb679420b999aa63c1b34dd0e0075cf9c5fd Author: Philip Herron <philip.herron@embecosm.com> Date: Wed May 4 13:48:03 2022 +0100 Fix size used in unsized adjustments When we coerce from an array to a slice we take the full capacity of the array as the size to the FatPtr slice object but this was off by one. This The TYPE_MAX_VALUE is not the correct method of accessing this but instead it needs to take into account other values to get the correct HOST_WIDE_INT Diff: --- gcc/rust/backend/rust-compile-expr.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 41f8c0a5ce4..1cf4e3d5499 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1348,7 +1348,13 @@ HIRCompileBase::resolve_unsized_adjustment (Resolver::Adjustment &adjustment, // fetch the size from the domain tree domain = TYPE_DOMAIN (expr_type); - tree size = TYPE_MAX_VALUE (domain); + unsigned HOST_WIDE_INT array_size + = wi::ext (wi::to_offset (TYPE_MAX_VALUE (domain)) + - wi::to_offset (TYPE_MIN_VALUE (domain)) + 1, + TYPE_PRECISION (TREE_TYPE (domain)), + TYPE_SIGN (TREE_TYPE (domain))) + .to_uhwi (); + tree size = build_int_cst (size_type_node, array_size); return ctx->get_backend ()->constructor_expression (fat_pointer, false, {data, size}, -1, locus);
reply other threads:[~2022-06-08 12:43 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608124328.2ED5838936CA@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).