Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879). 85/189285/2
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 19 Jun 2017 13:27:48 +0000 (13:27 +0000)
committerMikhail Kashkarov <m.kashkarov@partner.samsung.com>
Thu, 18 Oct 2018 13:20:11 +0000 (16:20 +0300)
2017-06-19  Martin Liska  <mliska@suse.cz>

PR sanitizer/80879
* gimplify.c (gimplify_switch_expr):
Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST.
2017-06-19  Martin Liska  <mliska@suse.cz>

PR sanitizer/80879
* gcc.dg/asan/use-after-scope-switch-4.c: New test.

upstream hash: dfbe80905a8674b4b1be4bf9181e824b37ffa33a
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249368 138bc75d-0d04-0410-961f-82ee72b054a4

Change-Id: I64057623544d67381f52230ba75a9fa804eb6eb2

gcc/gimplify.c
gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c [new file with mode: 0644]

index b8928d3..bd48300 100644 (file)
@@ -2241,7 +2241,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 (file)
index 0000000..290a920
--- /dev/null
@@ -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" } }  */