Hi!

As the following testcase shows, during var-tracking we can end trying to
delegitimize e.g. (plus:SI (unspec:SI ... UNSPEC_SET_GOT)
(const:SI (unspec:SI (symbol_ref:SI ...) UNSPEC_GOTOFF)).  The code is
prepared to handle PIC register + UNSPEC_GOTOFF, delegitimizing that
to the underlying SYMBOL_REF, but we can end up with the UNSPEC_SET_GOT
instead of the %ebx etc. register, because in the RTL that register
is initialized to that UNSPEC_SET_GOT.

The following patch handles it like the pic register; the
ix86_pic_register_p function is used only in the delegitimization hook.

Bootstrapped/regtested on x86_64-linux and i686-linux, the patch removed
all 170 non-delegitimized UNSPEC messages from x86_64-linux bootstrap and
142 out of 144 non-delegitimized UNSPEC messages from i686-linux bootstrap,
ok for trunk?

2019-01-24  Jakub Jelinek  <ja...@redhat.com>

        PR debug/89006
        * config/i386/i386.c (ix86_pic_register_p): Return true for
        UNSPEC_SET_GOT too.

        * g++.dg/debug/pr89006.C: New test.

--- gcc/config/i386/i386.c.jj   2019-01-22 23:26:46.668212957 +0100
+++ gcc/config/i386/i386.c      2019-01-24 11:51:40.050801078 +0100
@@ -16972,6 +16972,8 @@ ix86_pic_register_p (rtx x)
   if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
     return (pic_offset_table_rtx
            && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
+  else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_SET_GOT)
+    return true;
   else if (!REG_P (x))
     return false;
   else if (pic_offset_table_rtx)
--- gcc/testsuite/g++.dg/debug/pr89006.C.jj     2019-01-24 12:18:59.119838677 
+0100
+++ gcc/testsuite/g++.dg/debug/pr89006.C        2019-01-24 12:16:56.642859109 
+0100
@@ -0,0 +1,20 @@
+// PR debug/89006
+// { dg-do compile }
+// { dg-options "-O2 -g -w" }
+// { dg-additional-options "-fPIC" { target fpic } }
+// { dg-bogus "non-delegitimized UNSPEC UNSPEC_SET_GOT" "" { target { i?86-*-* 
x86_64-*-* } } 0 }
+
+struct A { A (bool); };
+
+static void
+foo (const char *x)
+{
+  new A (x);
+}
+
+void
+bar ()
+{
+  foo ("foo");
+  foo ("bar");
+}

        Jakub

Reply via email to