From: Jakub Jelinek <jakub@redhat.com>
To: Alexandre Oliva <aoliva@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [committed] Fix valgrind error in cselib_record_sets (PR rtl-optimization/88478)
Date: Fri, 14 Dec 2018 23:20:00 -0000 [thread overview]
Message-ID: <20181214231957.GV12380@tucnak> (raw)
In-Reply-To: <ord0qg79hw.fsf@lxoliva.fsfla.org>
Hi!
On Wed, Dec 05, 2018 at 04:50:19AM -0200, Alexandre Oliva wrote:
> * 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)
This regresses following testcase under valgrind on x86_64-linux.
The problem is that sets[i].src_elt is only conditionally initialized before
this:
/* We don't know how to record anything but REG or MEM. */
if (REG_P (dest)
|| (MEM_P (dest) && cselib_record_memory))
{
rtx src = sets[i].src;
if (cond)
src = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), cond, src, dest);
sets[i].src_elt = cselib_lookup (src, GET_MODE (dest), 1, VOIDmode);
...
}
otherwise it is uninitialized. So, we need to test it after REG_P (dest)
two lines after it.
Tested on x86_64-linux, committed to trunk as obvious.
2018-12-15 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/88478
* cselib.c (cselib_record_sets): Move sets[i].src_elt tests
after REG_P (dest) test.
* g++.dg/opt/pr88478.C: New test.
--- gcc/cselib.c.jj 2018-12-07 00:23:15.722987285 +0100
+++ gcc/cselib.c 2018-12-15 00:10:16.779762222 +0100
@@ -2616,10 +2616,10 @@ 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)
+ && sets[i].src_elt
&& is_a <scalar_int_mode> (GET_MODE (dest), &mode)
&& n_sets + n_strict_low_parts < MAX_SETS)
{
--- gcc/testsuite/g++.dg/opt/pr88478.C.jj 2018-12-15 00:14:14.427927166 +0100
+++ gcc/testsuite/g++.dg/opt/pr88478.C 2018-12-15 00:12:20.762761443 +0100
@@ -0,0 +1,17 @@
+// PR rtl-optimization/88478
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct A {
+ bool b;
+ int s;
+ template <typename T, typename U>
+ A (T, U) {}
+};
+enum F {} f;
+
+A
+foo ()
+{
+ return A (false, f);
+}
Jakub
prev parent reply other threads:[~2018-12-14 23:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 6:50 avoid null ptr deref in cselib_record_sets Alexandre Oliva
2018-12-05 8:32 ` Jakub Jelinek
2018-12-14 23:20 ` Jakub Jelinek [this message]
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=20181214231957.GV12380@tucnak \
--to=jakub@redhat.com \
--cc=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).