Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879).
authorMartin Liska <mliska@suse.cz>
Mon, 19 Jun 2017 13:27:48 +0000 (15:27 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Mon, 19 Jun 2017 13:27:48 +0000 (13:27 +0000)
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.

From-SVN: r249368

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

index 6ddc1717c8c7b09c6e563746e807e839e1f73941..aab38b1ce78edeaa411a078ba43a27467eff608b 100644 (file)
@@ -1,3 +1,9 @@
+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>
 
        * doc/install.texi: Document that PGO runs in 4 stages.
index 9af95a28704731fc30c3309de0950d934d204500..cf82f95160a22c0210fafbbb95c74c4b72535983 100644 (file)
@@ -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;
index 0b55fe02fab0a5d7110302696b4d07905b560228..26e527c7e153d1cf44f1cab870584ac723c6a7e7 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-19  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/80879
+       * gcc.dg/asan/use-after-scope-switch-4.c: New test.
+
 2017-06-19  Martin Liska  <mliska@suse.cz>
 
        PR ipa/80732
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" } }  */