diff options
author | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-11-10 11:21:03 +0000 |
---|---|---|
committer | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-11-10 11:21:03 +0000 |
commit | 65dc25166f86f75a85141e56344f482d41f3b024 (patch) | |
tree | 0faecaf07602821af5795a732245a4732a1147c4 | |
parent | c74b2e3bf07879b8b4f96bc51310240b12291545 (diff) | |
download | gcc-65dc25166f86f75a85141e56344f482d41f3b024.tar.gz |
Create live_switch_vars conditionally (PR sanitizer/78270)
PR sanitizer/78270
* gcc.dg/asan/pr78270.c: New test.
PR sanitizer/78270
* gimplify.c (gimplify_switch_expr): Create live_switch_vars
only when SWITCH_BODY is a BIND_EXPR.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@242036 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/gimplify.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/asan/pr78270.c | 13 |
4 files changed, 39 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f5c9add7720..b90789edc5d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-11-10 Martin Liska <mliska@suse.cz> + + PR sanitizer/78270 + * gimplify.c (gimplify_switch_expr): Create live_switch_vars + only when SWITCH_BODY is a BIND_EXPR. + 2016-11-10 Pierre-Marie de Rodat <derodat@adacore.com> PR debug/78112 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index d392450ddf5..da60c053de2 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2241,7 +2241,7 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) { vec<tree> labels; vec<tree> saved_labels; - hash_set<tree> *saved_live_switch_vars; + hash_set<tree> *saved_live_switch_vars = NULL; tree default_case = NULL_TREE; gswitch *switch_stmt; @@ -2253,8 +2253,14 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) labels. Save all the things from the switch body to append after. */ saved_labels = gimplify_ctxp->case_labels; gimplify_ctxp->case_labels.create (8); - saved_live_switch_vars = gimplify_ctxp->live_switch_vars; - gimplify_ctxp->live_switch_vars = new hash_set<tree> (4); + + /* Do not create live_switch_vars if SWITCH_BODY is not a BIND_EXPR. */ + 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<tree> (4); + } + bool old_in_switch_expr = gimplify_ctxp->in_switch_expr; gimplify_ctxp->in_switch_expr = true; @@ -2269,8 +2275,12 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) labels = gimplify_ctxp->case_labels; gimplify_ctxp->case_labels = saved_labels; - gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 0); - delete gimplify_ctxp->live_switch_vars; + + if (gimplify_ctxp->live_switch_vars) + { + gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 0); + delete gimplify_ctxp->live_switch_vars; + } gimplify_ctxp->live_switch_vars = saved_live_switch_vars; preprocess_case_label_vec_for_gimple (labels, index_type, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9dfd15c5e45..595021f3274 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-10 Martin Liska <mliska@suse.cz> + + PR sanitizer/78270 + * gcc.dg/asan/pr78270.c: New test. + 2016-11-10 Pierre-Marie de Rodat <derodat@adacore.com> Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/testsuite/gcc.dg/asan/pr78270.c b/gcc/testsuite/gcc.dg/asan/pr78270.c new file mode 100644 index 00000000000..55840b0ad6a --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr78270.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-additional-options "-Wno-switch-unreachable" } + +typedef struct +{ +} bdaddr_t; + +int a; +void fn1 () +{ + switch (a) + &(bdaddr_t){}; +} |