This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] Fix valgrind error in cselib_record_sets (PR rtl-optimization/88478)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]