From fb4b852a17656309e6acfb8da97cf9bce4b3b176 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 9 Nov 2016 11:52:00 +0100
Subject: [PATCH] Create live_switch_vars conditionally (PR sanitizer/78270)
gcc/testsuite/ChangeLog:
2016-11-09 Martin Liska <mliska@suse.cz>
* gcc.dg/asan/pr78269.c: New test.
gcc/ChangeLog:
2016-11-09 Martin Liska <mliska@suse.cz>
* gimplify.c (gimplify_switch_expr): Create live_switch_vars
only when SWITCH_BODY is a BIND_EXPR.
---
gcc/gimplify.c | 20 +++++++++++++++-----
gcc/testsuite/gcc.dg/asan/pr78269.c | 13 +++++++++++++
2 files changed, 28 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/asan/pr78269.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,
new file mode 100644
@@ -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){};
+}
--
2.10.1