diff mbox

Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879).

Message ID 08849f53-06b3-ab85-d524-7d291d9ab509@suse.cz
State New
Headers show

Commit Message

Martin Liška May 26, 2017, 11:05 a.m. UTC
Hello.

Unfortunately I guarded use-after-scope to track live switch variables just
to BIND_EXPR. However the bind expression can be included in a STATEMENT_LIST.
That enables proper tracking and fixes the test added.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

Comments

Martin Liška June 6, 2017, 6:58 a.m. UTC | #1
PING^1

On 05/26/2017 01:05 PM, Martin Liška wrote:
> Hello.
> 
> Unfortunately I guarded use-after-scope to track live switch variables just
> to BIND_EXPR. However the bind expression can be included in a STATEMENT_LIST.
> That enables proper tracking and fixes the test added.
> 
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
> 
> Ready to be installed?
> Martin
>
Martin Liška June 19, 2017, 10:24 a.m. UTC | #2
PING^2

On 06/06/2017 08:58 AM, Martin Liška wrote:
> PING^1
> 
> On 05/26/2017 01:05 PM, Martin Liška wrote:
>> Hello.
>>
>> Unfortunately I guarded use-after-scope to track live switch variables just
>> to BIND_EXPR. However the bind expression can be included in a STATEMENT_LIST.
>> That enables proper tracking and fixes the test added.
>>
>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>>
>> Ready to be installed?
>> Martin
>>
>
Jakub Jelinek June 19, 2017, 1:23 p.m. UTC | #3
On Fri, May 26, 2017 at 01:05:28PM +0200, Martin Liška wrote:
> Hello.
> 
> Unfortunately I guarded use-after-scope to track live switch variables just
> to BIND_EXPR. However the bind expression can be included in a STATEMENT_LIST.
> That enables proper tracking and fixes the test added.
> 
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
> 
> Ready to be installed?
> Martin

> >From a7f63e228118b3f256d9e774fdeeb8c85c0da437 Mon Sep 17 00:00:00 2001
> From: marxin <mliska@suse.cz>
> Date: Thu, 25 May 2017 17:53:06 +0200
> Subject: [PATCH] Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST
>  (PR sanitizer/80879).
> 
> gcc/ChangeLog:
> 
> 2017-05-25  Martin Liska  <mliska@suse.cz>
> 
> 	* gimplify.c (gimplify_switch_expr):
> 	Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST.
> 
> gcc/testsuite/ChangeLog:
> 
> 2017-05-25  Martin Liska  <mliska@suse.cz>
> 
> 	* gcc.dg/asan/use-after-scope-switch-4.c: New test.

Ok, thanks.

	Jakub
diff mbox

Patch

From a7f63e228118b3f256d9e774fdeeb8c85c0da437 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 25 May 2017 17:53:06 +0200
Subject: [PATCH] Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST
 (PR sanitizer/80879).

gcc/ChangeLog:

2017-05-25  Martin Liska  <mliska@suse.cz>

	* gimplify.c (gimplify_switch_expr):
	Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST.

gcc/testsuite/ChangeLog:

2017-05-25  Martin Liska  <mliska@suse.cz>

	* gcc.dg/asan/use-after-scope-switch-4.c: New test.
---
 gcc/gimplify.c                                     |  3 +-
 .../gcc.dg/asan/use-after-scope-switch-4.c         | 35 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 455a6993e15..0983ebef298 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2279,7 +2279,8 @@  gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
 
       /* Do not create live_switch_vars if SWITCH_BODY is not a BIND_EXPR.  */
       saved_live_switch_vars = gimplify_ctxp->live_switch_vars;
-      if (TREE_CODE (SWITCH_BODY (switch_expr)) == BIND_EXPR)
+      tree_code body_type = TREE_CODE (SWITCH_BODY (switch_expr));
+      if (body_type == BIND_EXPR || body_type == STATEMENT_LIST)
 	gimplify_ctxp->live_switch_vars = new hash_set<tree> (4);
       else
 	gimplify_ctxp->live_switch_vars = NULL;
diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c
new file mode 100644
index 00000000000..290a920633b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c
@@ -0,0 +1,35 @@ 
+// { dg-do run }
+// { dg-additional-options "-fdump-tree-gimple" }
+
+int *ptr;
+
+struct a
+{
+  int c;
+};
+
+int main(int argc, char **argv)
+{
+  struct a e;
+  e.c = 2;
+  int x = 0;
+
+  for (;;)
+    switch (e.c)    
+      case 3:
+	{
+	  int resxxx;
+	case 2:
+	  ptr = &resxxx;
+	  *ptr = 123;
+
+	  if (x)
+	    return 0;
+	  else
+	    x = 1;
+	}
+
+  return 1;
+}
+
+/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &resxxx, \[0-9\]\\);" 2 "gimple" } }  */
-- 
2.12.2