diff mbox

[Committed] S/390: Fix BZ 59803.

Message ID 20140115093453.GA16500@bart
State New
Headers show

Commit Message

Andreas Krebbel Jan. 15, 2014, 9:34 a.m. UTC
Hi,

fix for BZ59803.  For more details please see the comment in the
patch.

Bootstrapped and regtested on s390x with 4.8 and mainline.

Committed to 4.8 and mainline.

Bye,

-Andreas-

2014-01-15  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>

	* config/s390/s390.c (s390_preferred_reload_class): Don't return
	ADDR_REGS for invalid symrefs in non-PIC code.
diff mbox

Patch

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index d0e0f31..257e33c 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -3115,15 +3115,22 @@  s390_preferred_reload_class (rtx op, reg_class_t rclass)
 	 prefer ADDR_REGS.  If 'class' is not a superset
 	 of ADDR_REGS, e.g. FP_REGS, reject this reload.  */
       case CONST:
-	/* A larl operand with odd addend will get fixed via secondary
-	   reload.  So don't request it to be pushed into literal
-	   pool.  */
+	/* Symrefs cannot be pushed into the literal pool with -fPIC
+	   so we *MUST NOT* return NO_REGS for these cases
+	   (s390_cannot_force_const_mem will return true).  
+
+	   On the other hand we MUST return NO_REGS for symrefs with
+	   invalid addend which might have been pushed to the literal
+	   pool (no -fPIC).  Usually we would expect them to be
+	   handled via secondary reload but this does not happen if
+	   they are used as literal pool slot replacement in reload
+	   inheritance (see emit_input_reload_insns).  */
 	if (TARGET_CPU_ZARCH
 	    && GET_CODE (XEXP (op, 0)) == PLUS
 	    && GET_CODE (XEXP (XEXP(op, 0), 0)) == SYMBOL_REF
 	    && GET_CODE (XEXP (XEXP(op, 0), 1)) == CONST_INT)
 	  {
-	    if (reg_class_subset_p (ADDR_REGS, rclass))
+	    if (flag_pic && reg_class_subset_p (ADDR_REGS, rclass))
 	      return ADDR_REGS;
 	    else
 	      return NO_REGS;
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr59803.c b/gcc/testsuite/gcc.c-torture/compile/pr59803.c
new file mode 100644
index 0000000..d2b5d20
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr59803.c
@@ -0,0 +1,27 @@ 
+/* PR target/59803 */
+
+extern void baz (void) __attribute__ ((__noreturn__));
+struct A { int g, h; };
+extern struct A a;
+struct B { unsigned char i, j, k, l, m; };
+int c, d, e;
+static int f;
+
+void
+foo (void)
+{
+  f = 1;
+}
+
+void
+bar (struct B *x)
+{
+  x->i = e;
+  x->k = c;
+  x->l = d;
+  x->j = a.h;
+  x->m = f;
+  if (x->i != e) baz ();
+  if (x->k != c) baz ();
+  if (x->j != a.h) baz ();
+}