From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>,
Ilya Enkovich <enkovich.gnu@gmail.com>,
Alexander Ivchenko <aivchenk@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix UB in tree-chkp.c
Date: Mon, 19 Jun 2017 17:43:00 -0000 [thread overview]
Message-ID: <20170619174345.GW2123@tucnak> (raw)
Hi!
bootstrap-ubsan shows a couple of:
../../gcc/tree-chkp.c:694:37: runtime error: shift exponent 63 is too large for 32-bit type 'int'
errors.
1 << (TYPE_PRECISION (ptr_type_node) - 1)
should have been obviously
HOST_WIDE_INT_1U << (TYPE_PRECISION (ptr_type_node) - 1)
but even then, it is 1) unnecessarily complicated and expensive way
to create a pointer with just the MSB bit set and all other clear and
2) will not work if ptr_type_node has higher precision than HWI (just
theoretical possibility now)
For 1), e.g. fold_convert (ptr_type_node, integer_zero_node) is
better written as build_int_cst (ptr_type_node, 0), but still
we can actually avoid the fold_build_pointer_plus_hwi and folding
it altogether.
Bootstrapped/regtested on x86_64-linux and i686-linux (both normal
and bootstrap-ubsan), ok for trunk?
2017-07-19 Jakub Jelinek <jakub@redhat.com>
* tree-chkp.c (chkp_get_hard_register_var_fake_base_address):
Rewritten to avoid overflow for > 32-bit pointers.
--- gcc/tree-chkp.c.jj 2017-06-12 12:41:55.000000000 +0200
+++ gcc/tree-chkp.c 2017-06-19 12:57:24.670478544 +0200
@@ -690,9 +690,8 @@ chkp_erase_completed_bounds (void)
static tree
chkp_get_hard_register_var_fake_base_address ()
{
- tree base = fold_convert (ptr_type_node, integer_zero_node);
- unsigned HOST_WIDE_INT offset = 1 << (TYPE_PRECISION (ptr_type_node) - 1);
- return fold_build_pointer_plus_hwi (base, offset);
+ int prec = TYPE_PRECISION (ptr_type_node);
+ return wide_int_to_tree (ptr_type_node, wi::min_value (prec, SIGNED));
}
/* If we check bounds for a hard register variable, we cannot
Jakub
next reply other threads:[~2017-06-19 17:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-19 17:43 Jakub Jelinek [this message]
2017-06-19 18:01 ` Ilya Enkovich
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=20170619174345.GW2123@tucnak \
--to=jakub@redhat.com \
--cc=aivchenk@gmail.com \
--cc=enkovich.gnu@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
/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: link
Be 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).