From 037f5c0adf25b4487ca4c0621f26fb6171b40f07 Mon Sep 17 00:00:00 2001 From: marxin Date: Wed, 16 Nov 2016 11:56:58 +0000 Subject: [PATCH] Fix PR sanitizer/78270 (part 2) PR sanitizer/78270 * gimplify.c (gimplify_switch_expr): Always save previous gimplify_ctxp->live_switch_vars. PR sanitizer/78270 * gcc.dg/asan/pr78270.c: Update comment style. * gcc.dg/asan/pr78270-2.c: New test. upstream hash: 904e262bdb88c2cf1eefeb4997c8d4ed2a888d55 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@242485 138bc75d-0d04-0410-961f-82ee72b054a4 Change-Id: I760170bff746390269035dd2c10afff960d06445 --- gcc/gimplify.c | 8 ++++---- gcc/testsuite/gcc.dg/asan/pr78270-2.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/asan/pr78270.c | 5 +++-- 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/asan/pr78270-2.c diff --git a/gcc/gimplify.c b/gcc/gimplify.c index c294390..673738c 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2240,11 +2240,11 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) gimplify_ctxp->case_labels.create (8); /* 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) - { - saved_live_switch_vars = gimplify_ctxp->live_switch_vars; - gimplify_ctxp->live_switch_vars = new hash_set (4); - } + gimplify_ctxp->live_switch_vars = new hash_set (4); + else + gimplify_ctxp->live_switch_vars = NULL; bool old_in_switch_expr = gimplify_ctxp->in_switch_expr; gimplify_ctxp->in_switch_expr = true; diff --git a/gcc/testsuite/gcc.dg/asan/pr78270-2.c b/gcc/testsuite/gcc.dg/asan/pr78270-2.c new file mode 100644 index 0000000..72195b3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr78270-2.c @@ -0,0 +1,18 @@ +/* PR sanitizer/78270 */ +/* { dg-do compile } */ +/* { dg-additional-options "-Wno-switch-unreachable" } */ + +int a; +void +fn1 () +{ + switch (a) + { + char b; + case 8: + &b; + switch (0) + ; + } +} + diff --git a/gcc/testsuite/gcc.dg/asan/pr78270.c b/gcc/testsuite/gcc.dg/asan/pr78270.c index 55840b0..5583ce4 100644 --- a/gcc/testsuite/gcc.dg/asan/pr78270.c +++ b/gcc/testsuite/gcc.dg/asan/pr78270.c @@ -1,5 +1,6 @@ -// { dg-do compile } -// { dg-additional-options "-Wno-switch-unreachable" } +/* PR sanitizer/78270 */ +/* { dg-do compile } */ +/* { dg-additional-options "-Wno-switch-unreachable" } */ typedef struct { -- 2.7.4