From: Alexandre Oliva <aoliva@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: avoid null ptr deref in cselib_record_sets
Date: Wed, 05 Dec 2018 06:50:00 -0000 [thread overview]
Message-ID: <ord0qg79hw.fsf@lxoliva.fsfla.org> (raw)
Jeff Law tells me h8300-elf fails gcc.c-torture/compile/pr49029.c
with -O2 -g -mint32 -mh. This patch fixes it.
The problem is that strict low part handling in cselib_record_sets
assumes src_elt is not NULL. That src_elt is taken from a strict low
part set, but it won't always have a src_elt to begin with. In this
case, it's because src is a volatile MEM; we don't record values for
those.
Although we could fix the problem by testing for a NULL src_elt before
creating the zero extends corresponding to strict low part sets of
formerly const0_rtx REGs, there's no point in recording the additional
set that we won't be able to use anyway.
We could still record that the whole register has a zero-extend of
the value stored in the narrower-mode strict low part of the register,
but is that of any use? I guess not, but if we find otherwise, we can
change that later.
Jeff tested this with a cross compiler to h8300-elf, and several other
native and cross toolchains IIUC. I'm regstrapping it myself on i686-
and x86_64-linux-gnu. Ok to install?
for gcc/ChangeLog
* cselib.c (cselib_record_sets): Skip strict low part sets
with NULL src_elt.
---
gcc/cselib.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/gcc/cselib.c b/gcc/cselib.c
index 6d3a4078c689..4a68439455fd 100644
--- a/gcc/cselib.c
+++ b/gcc/cselib.c
@@ -2616,6 +2616,7 @@ cselib_record_sets (rtx_insn *insn)
preserves the upper bits that di:SI=zero_extend(flags:CCNO<=0). */
scalar_int_mode mode;
if (dest != orig
+ && sets[i].src_elt
&& cselib_record_sets_hook
&& REG_P (dest)
&& HARD_REGISTER_P (dest)
--
Alexandre Oliva, freedom fighter https://FSFLA.org/blogs/lxo
Be the change, be Free! FSF Latin America board member
GNU Toolchain Engineer Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe
next reply other threads:[~2018-12-05 6:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 6:50 Alexandre Oliva [this message]
2018-12-05 8:32 ` Jakub Jelinek
2018-12-14 23:20 ` [committed] Fix valgrind error in cselib_record_sets (PR rtl-optimization/88478) Jakub Jelinek
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=ord0qg79hw.fsf@lxoliva.fsfla.org \
--to=aoliva@redhat.com \
--cc=gcc-patches@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: 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).