diff mbox

Fix handling of computed goto in tree-nested.c (PR middle-end/71494)

Message ID 20160610191309.GH7387@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek June 10, 2016, 7:13 p.m. UTC
Hi!

As can be seen on the following (IMNSHO valid) testcase, we need to walk
ops of GIMPLE_GOTO, except when it has (non-local) LABEL_DECL in it.
There is code to do this, but it was setting *handled_ops_p to true and
thus not actually walking those (therefore tweaks of wi->* were useless).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2016-06-10  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/71494
	* tree-nested.c (convert_nonlocal_reference_stmt): For GIMPLE_GOTO
	without LABEL_DECL, set *handled_ops_p to false instead of true.

	* gcc.c-torture/execute/pr71494.c: New test.


	Jakub

Comments

Richard Biener June 10, 2016, 7:29 p.m. UTC | #1
On June 10, 2016 9:13:09 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>As can be seen on the following (IMNSHO valid) testcase, we need to
>walk
>ops of GIMPLE_GOTO, except when it has (non-local) LABEL_DECL in it.
>There is code to do this, but it was setting *handled_ops_p to true and
>thus not actually walking those (therefore tweaks of wi->* were
>useless).
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?

OK.

Thanks 
Richard.

>2016-06-10  Jakub Jelinek  <jakub@redhat.com>
>
>	PR middle-end/71494
>	* tree-nested.c (convert_nonlocal_reference_stmt): For GIMPLE_GOTO
>	without LABEL_DECL, set *handled_ops_p to false instead of true.
>
>	* gcc.c-torture/execute/pr71494.c: New test.
>
>--- gcc/tree-nested.c.jj	2016-04-22 18:21:54.000000000 +0200
>+++ gcc/tree-nested.c	2016-06-10 13:29:24.227858894 +0200
>@@ -1332,7 +1332,7 @@ convert_nonlocal_reference_stmt (gimple_
> 	{
> 	  wi->val_only = true;
> 	  wi->is_lhs = false;
>-	  *handled_ops_p = true;
>+	  *handled_ops_p = false;
> 	  return NULL_TREE;
> 	}
>       break;
>--- gcc/testsuite/gcc.c-torture/execute/pr71494.c.jj	2016-06-10
>13:33:04.776955077 +0200
>+++ gcc/testsuite/gcc.c-torture/execute/pr71494.c	2016-06-10
>13:32:43.000000000 +0200
>@@ -0,0 +1,22 @@
>+/* PR middle-end/71494 */
>+
>+int
>+main ()
>+{
>+  void *label = &&out;
>+  int i = 0;
>+  void test (void)
>+  {
>+    label = &&out2;
>+    goto *label;
>+   out2:;
>+    i++;
>+  }
>+  goto *label;
>+ out:
>+  i += 2;
>+  test ();
>+  if (i != 3)
>+    __builtin_abort ();
>+  return 0;
>+}
>
>	Jakub
Jeff Law June 10, 2016, 7:30 p.m. UTC | #2
On 06/10/2016 01:13 PM, Jakub Jelinek wrote:
> Hi!
>
> As can be seen on the following (IMNSHO valid) testcase, we need to walk
> ops of GIMPLE_GOTO, except when it has (non-local) LABEL_DECL in it.
> There is code to do this, but it was setting *handled_ops_p to true and
> thus not actually walking those (therefore tweaks of wi->* were useless).
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2016-06-10  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR middle-end/71494
> 	* tree-nested.c (convert_nonlocal_reference_stmt): For GIMPLE_GOTO
> 	without LABEL_DECL, set *handled_ops_p to false instead of true.
>
> 	* gcc.c-torture/execute/pr71494.c: New test.
OK.

Note the following from the labels as values section of the manual:

--
You may not use this mechanism to jump to code in a different function.
If you do that, totally unpredictable things happen.  The best way to
avoid this is to store the label address only in automatic variables and
never pass it as an argument.
--

Which I think says pretty explicitly that the original testcase is invalid.

jeff
diff mbox

Patch

--- gcc/tree-nested.c.jj	2016-04-22 18:21:54.000000000 +0200
+++ gcc/tree-nested.c	2016-06-10 13:29:24.227858894 +0200
@@ -1332,7 +1332,7 @@  convert_nonlocal_reference_stmt (gimple_
 	{
 	  wi->val_only = true;
 	  wi->is_lhs = false;
-	  *handled_ops_p = true;
+	  *handled_ops_p = false;
 	  return NULL_TREE;
 	}
       break;
--- gcc/testsuite/gcc.c-torture/execute/pr71494.c.jj	2016-06-10 13:33:04.776955077 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr71494.c	2016-06-10 13:32:43.000000000 +0200
@@ -0,0 +1,22 @@ 
+/* PR middle-end/71494 */
+
+int
+main ()
+{
+  void *label = &&out;
+  int i = 0;
+  void test (void)
+  {
+    label = &&out2;
+    goto *label;
+   out2:;
+    i++;
+  }
+  goto *label;
+ out:
+  i += 2;
+  test ();
+  if (i != 3)
+    __builtin_abort ();
+  return 0;
+}