diff mbox series

[committed] Fix minor stack-clash failures on x86

Message ID 8adafcd4-74c1-c198-23e8-b1af9840fb5a@redhat.com
State New
Headers show
Series [committed] Fix minor stack-clash failures on x86 | expand

Commit Message

Jeff Law Sept. 20, 2017, 10:02 p.m. UTC
Jakub (and likely HJ) ran into a case where the stack clash code was
looking at the INTVAL of an object that wasn't actually a CONST_INT.  I
won't start my rant about why this shouldn't be possible.

Anyway, this patch fixes that and turns several == CONST_INT tests to
use CONST_INT_P.

This also fixes the x86 specific stack-clash test so that it works for
both i?86 and x86_64.

Bootstrapped and regression tested (with rtl checking this time!).

Installing on the trunk.

jeff
diff mbox series

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 371b7902f37..9f0c821fc65 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@ 
+2017-09-20  Jeff Law  <law@redhat.com>
+
+	* explow.c (compute_stack_clash_protection_loop_data): Use
+	CONST_INT_P instead of explicit test.  Verify object is a
+	CONST_INT_P before looking at INTVAL.
+	(anti_adjust_stack_and_probe_stack_clash): Use CONST_INT_P
+	instead of explicit test.
+
 2017-09-20  Segher Boessenkool  <segher@kernel.crashing.org>
 
 	PR target/77687
diff --git a/gcc/explow.c b/gcc/explow.c
index 0f30507d1f5..6131d1810cb 100644
--- a/gcc/explow.c
+++ b/gcc/explow.c
@@ -1834,11 +1834,11 @@  compute_stack_clash_protection_loop_data (rtx *rounded_size, rtx *last_addr,
       if (*rounded_size == CONST0_RTX (Pmode))
 	fprintf (dump_file,
 		 "Stack clash skipped dynamic allocation and probing loop.\n");
-      else if (GET_CODE (*rounded_size) == CONST_INT
+      else if (CONST_INT_P (*rounded_size)
 	       && INTVAL (*rounded_size) <= 4 * *probe_interval)
 	fprintf (dump_file,
 		 "Stack clash dynamic allocation and probing inline.\n");
-      else if (GET_CODE (*rounded_size) == CONST_INT)
+      else if (CONST_INT_P (*rounded_size))
 	fprintf (dump_file,
 		 "Stack clash dynamic allocation and probing in "
 		 "rotated loop.\n");
@@ -1936,7 +1936,8 @@  anti_adjust_stack_and_probe_stack_clash (rtx size)
 
   if (rounded_size != CONST0_RTX (Pmode))
     {
-      if (INTVAL (rounded_size) <= 4 * probe_interval)
+      if (CONST_INT_P (rounded_size)
+	  && INTVAL (rounded_size) <= 4 * probe_interval)
 	{
 	  for (HOST_WIDE_INT i = 0;
 	       i < INTVAL (rounded_size);
@@ -1956,7 +1957,7 @@  anti_adjust_stack_and_probe_stack_clash (rtx size)
       else
 	{
 	  rtx loop_lab, end_loop;
-	  bool rotate_loop = GET_CODE (rounded_size) == CONST_INT;
+	  bool rotate_loop = CONST_INT_P (rounded_size);
 	  emit_stack_clash_protection_probe_loop_start (&loop_lab, &end_loop,
 							last_addr, rotate_loop);
 
@@ -1994,7 +1995,7 @@  anti_adjust_stack_and_probe_stack_clash (rtx size)
 	 might hold live data.  So probe at *sp if we know that
 	 an allocation was made, otherwise probe into the red zone
 	 which is obviously undesirable.  */
-      if (GET_CODE (size) == CONST_INT)
+      if (CONST_INT_P (size))
 	{
 	  emit_stack_probe (stack_pointer_rtx);
 	  emit_insn (gen_blockage ());
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index eebb33d0b96..a636327cd93 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2017-09-20  Jeff Law  <law@redhat.com>
+
+	* gcc.target/i386/stack-check-11.c: Update test and regexp
+	so that it works for both i?86 and x86_64.
+
 2017-09-19  Segher Boessenkool  <segher@kernel.crashing.org>
 
 	PR target/77687
diff --git a/gcc/testsuite/gcc.target/i386/stack-check-11.c b/gcc/testsuite/gcc.target/i386/stack-check-11.c
index 183103f01e5..fe5b2c2b844 100644
--- a/gcc/testsuite/gcc.target/i386/stack-check-11.c
+++ b/gcc/testsuite/gcc.target/i386/stack-check-11.c
@@ -2,15 +2,17 @@ 
 /* { dg-options "-O2 -fstack-clash-protection" } */
 /* { dg-require-effective-target supports_stack_clash_protection } */
 
-extern void arf (unsigned long int *, unsigned long int *);
+#include <stdint.h>
+
+extern void arf (uint64_t *, uint64_t *);
 void
 frob ()
 {
-  unsigned long int num[859];
-  unsigned long int den[859];
+  uint64_t num[859];
+  uint64_t den[859];
   arf (den, num);
 }
 
-/* { dg-final { scan-assembler-times "subq" 4 } } */
-/* { dg-final { scan-assembler-times "orq" 3 } } */
+/* { dg-final { scan-assembler-times "sub\[ql\]" 4 } } */
+/* { dg-final { scan-assembler-times "or\[ql\]" 3 } } */