x86: Always update EH return address in word_mode

Message ID 20180820181900.GA27620@intel.com
State New
Headers show
Series
  • x86: Always update EH return address in word_mode
Related show

Commit Message

H.J. Lu Aug. 20, 2018, 6:19 p.m.
On x86, return address is always popped in word_mode.  eh_return needs
to put EH return address in word_mode on stack.

Tested on x86-64 with x32. OK for trunk and release branches?

Thanks.

H.J.
---
gcc/

	PR target/87014
	* config/i386/i386.md (eh_return): Always update EH return
	address in word_mode.

gcc/testsuite/

	PR target/87014
	* g++.dg/pr87014.C: New file.
---
 gcc/config/i386/i386.md        |  5 ++++-
 gcc/testsuite/g++.dg/pr87014.C | 38 ++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/pr87014.C

-- 
2.17.1

Comments

Uros Bizjak Aug. 20, 2018, 6:40 p.m. | #1
On Mon, Aug 20, 2018 at 8:19 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> On x86, return address is always popped in word_mode.  eh_return needs

> to put EH return address in word_mode on stack.

>

> Tested on x86-64 with x32. OK for trunk and release branches?


OK. Perhaps the testcase should go into g++.dg/torture, since it is
sensitive to optimization level?

Thanks,
Uros.

> Thanks.

>

> H.J.

> ---

> gcc/

>

>         PR target/87014

>         * config/i386/i386.md (eh_return): Always update EH return

>         address in word_mode.

>

> gcc/testsuite/

>

>         PR target/87014

>         * g++.dg/pr87014.C: New file.

> ---

>  gcc/config/i386/i386.md        |  5 ++++-

>  gcc/testsuite/g++.dg/pr87014.C | 38 ++++++++++++++++++++++++++++++++++

>  2 files changed, 42 insertions(+), 1 deletion(-)

>  create mode 100644 gcc/testsuite/g++.dg/pr87014.C

>

> diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md

> index 918241d953a..71faa218ffa 100644

> --- a/gcc/config/i386/i386.md

> +++ b/gcc/config/i386/i386.md

> @@ -13612,7 +13612,10 @@

>       stack address we wish to restore.  */

>    tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);

>    tmp = plus_constant (Pmode, tmp, -UNITS_PER_WORD);

> -  tmp = gen_rtx_MEM (Pmode, tmp);

> +  /* Return address is always in word_mode.  */

> +  tmp = gen_rtx_MEM (word_mode, tmp);

> +  if (GET_MODE (ra) != word_mode)

> +    ra = convert_to_mode (word_mode, ra, 1);

>    emit_move_insn (tmp, ra);

>

>    emit_jump_insn (gen_eh_return_internal ());

> diff --git a/gcc/testsuite/g++.dg/pr87014.C b/gcc/testsuite/g++.dg/pr87014.C

> new file mode 100644

> index 00000000000..060ec948c90

> --- /dev/null

> +++ b/gcc/testsuite/g++.dg/pr87014.C

> @@ -0,0 +1,38 @@

> +// { dg-do run }

> +// { dg-options "-O0" }

> +

> +void

> +fillstack ()

> +{

> +  long long foo[] =

> +    {

> +      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

> +    };

> +}

> +

> +void

> +f (long long=-1,long long=-1,long long=-1,long long=-1,

> +   long long=-1,long long=-1,long long arg7_on_stack=-1)

> +{

> +  throw 0;

> +}

> +

> +void

> +g()

> +{

> +  try

> +    {

> +      f ();

> +    }

> +  catch (int)

> +    {

> +    }

> +}

> +

> +int

> +main()

> +{

> +  fillstack ();

> +  g ();

> +  return 0;

> +}

> --

> 2.17.1

>
H.J. Lu Aug. 20, 2018, 7:11 p.m. | #2
On Mon, Aug 20, 2018 at 11:40 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Mon, Aug 20, 2018 at 8:19 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:

>> On x86, return address is always popped in word_mode.  eh_return needs

>> to put EH return address in word_mode on stack.

>>

>> Tested on x86-64 with x32. OK for trunk and release branches?

>

> OK. Perhaps the testcase should go into g++.dg/torture, since it is

> sensitive to optimization level?


Sure.  This is the patch I am checking in.

Thanks.

-- 
H.J.
From 62605355f506d4f163b6102ae0db67b19c3df756 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 20 Aug 2018 10:04:35 -0700
Subject: [PATCH] x86: Always update EH return address in word_mode

On x86, return address is always popped in word_mode.  eh_return needs
to put EH return address in word_mode on stack.

gcc/

	PR target/87014
	* config/i386/i386.md (eh_return): Always update EH return
	address in word_mode.

gcc/testsuite/

	PR target/87014
	* g++.dg/torture/pr87014.C: New file.
---
 gcc/config/i386/i386.md                |  5 +++-
 gcc/testsuite/g++.dg/torture/pr87014.C | 37 ++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr87014.C

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 918241d953a..71faa218ffa 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -13612,7 +13612,10 @@
      stack address we wish to restore.  */
   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
   tmp = plus_constant (Pmode, tmp, -UNITS_PER_WORD);
-  tmp = gen_rtx_MEM (Pmode, tmp);
+  /* Return address is always in word_mode.  */
+  tmp = gen_rtx_MEM (word_mode, tmp);
+  if (GET_MODE (ra) != word_mode)
+    ra = convert_to_mode (word_mode, ra, 1);
   emit_move_insn (tmp, ra);
 
   emit_jump_insn (gen_eh_return_internal ());
diff --git a/gcc/testsuite/g++.dg/torture/pr87014.C b/gcc/testsuite/g++.dg/torture/pr87014.C
new file mode 100644
index 00000000000..614954ef464
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr87014.C
@@ -0,0 +1,37 @@
+// { dg-do run }
+
+void
+fillstack ()
+{
+  long long foo[] =
+    {
+      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    };
+}
+
+void
+f (long long=-1,long long=-1,long long=-1,long long=-1,
+   long long=-1,long long=-1,long long arg7_on_stack=-1)
+{
+  throw 0;
+}
+
+void
+g()
+{
+  try
+    {
+      f ();
+    }
+  catch (int)
+    {
+    }
+}
+
+int
+main()
+{
+  fillstack ();
+  g ();
+  return 0;
+}

Patch

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 918241d953a..71faa218ffa 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -13612,7 +13612,10 @@ 
      stack address we wish to restore.  */
   tmp = gen_rtx_PLUS (Pmode, arg_pointer_rtx, sa);
   tmp = plus_constant (Pmode, tmp, -UNITS_PER_WORD);
-  tmp = gen_rtx_MEM (Pmode, tmp);
+  /* Return address is always in word_mode.  */
+  tmp = gen_rtx_MEM (word_mode, tmp);
+  if (GET_MODE (ra) != word_mode)
+    ra = convert_to_mode (word_mode, ra, 1);
   emit_move_insn (tmp, ra);
 
   emit_jump_insn (gen_eh_return_internal ());
diff --git a/gcc/testsuite/g++.dg/pr87014.C b/gcc/testsuite/g++.dg/pr87014.C
new file mode 100644
index 00000000000..060ec948c90
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr87014.C
@@ -0,0 +1,38 @@ 
+// { dg-do run }
+// { dg-options "-O0" }
+
+void
+fillstack ()
+{
+  long long foo[] =
+    {
+      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+    };
+}
+
+void
+f (long long=-1,long long=-1,long long=-1,long long=-1,
+   long long=-1,long long=-1,long long arg7_on_stack=-1)
+{
+  throw 0;
+}
+
+void
+g()
+{
+  try
+    {
+      f ();
+    }
+  catch (int)
+    {
+    }
+}
+
+int
+main()
+{
+  fillstack ();
+  g ();
+  return 0;
+}