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 <mli...@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 <mli...@suse.cz> * gimplify.c (gimplify_switch_expr): Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST. gcc/testsuite/ChangeLog: 2017-05-25 Martin Liska <mli...@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