From: Martin Liska Date: Mon, 19 Jun 2017 13:27:48 +0000 (+0200) Subject: Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a6e5212a77e34682cfb591ed80e7166eaa895365;p=gcc.git Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879). 2017-06-19 Martin Liska PR sanitizer/80879 * gimplify.c (gimplify_switch_expr): Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST. 2017-06-19 Martin Liska PR sanitizer/80879 * gcc.dg/asan/use-after-scope-switch-4.c: New test. From-SVN: r249368 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6ddc1717c8c..aab38b1ce78 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-06-19 Martin Liska + + PR sanitizer/80879 + * gimplify.c (gimplify_switch_expr): + Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST. + 2017-06-19 Martin Liska * doc/install.texi: Document that PGO runs in 4 stages. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 9af95a28704..cf82f95160a 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 (4); else gimplify_ctxp->live_switch_vars = NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0b55fe02fab..26e527c7e15 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-19 Martin Liska + + PR sanitizer/80879 + * gcc.dg/asan/use-after-scope-switch-4.c: New test. + 2017-06-19 Martin Liska 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 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" } } */