This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix VAR_DECL w/o a BIND_EXPR (PR sanitize/80659).
- From: Martin Liška <mliska at suse dot cz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 15 May 2017 12:17:56 +0200
- Subject: [PATCH] Fix VAR_DECL w/o a BIND_EXPR (PR sanitize/80659).
- Authentication-results: sourceware.org; auth=none
Hello.
There are situations where local variables (defined in a switch scope) do
not belong to any BIND_EXPR. Thus, we ICE due to gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 0);
Is there any better solution how we can catch these variables?
Suggested patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
Ready to be installed?
Martin
>From 3d906f714f9e56d1d8bc4c70464699c0742dc08c Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 12 May 2017 14:08:49 +0200
Subject: [PATCH] Fix VAR_DECL w/o a BIND_EXPR (PR sanitize/80659).
gcc/ChangeLog:
2017-05-12 Martin Liska <mliska@suse.cz>
PR sanitize/80659
* gimplify.c (gimplify_switch_expr): Do not assert as
we can have a VAR_DECL that does not belong to a BIND_EXPR.
gcc/testsuite/ChangeLog:
2017-05-12 Martin Liska <mliska@suse.cz>
PR sanitize/80659
* gcc.dg/asan/pr80659.c: New test.
---
gcc/gimplify.c | 5 +----
gcc/testsuite/gcc.dg/asan/pr80659.c | 10 ++++++++++
2 files changed, 11 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/asan/pr80659.c
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index a28a9af3b7f..32b1c9dfde2 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2297,10 +2297,7 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p)
gimplify_ctxp->case_labels = saved_labels;
if (gimplify_ctxp->live_switch_vars)
- {
- gcc_assert (gimplify_ctxp->live_switch_vars->elements () == 0);
- delete gimplify_ctxp->live_switch_vars;
- }
+ 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/gcc.dg/asan/pr80659.c b/gcc/testsuite/gcc.dg/asan/pr80659.c
new file mode 100644
index 00000000000..03281e9c221
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr80659.c
@@ -0,0 +1,10 @@
+/* PR sanitizer/80659 */
+/* { dg-do compile } */
+
+void foo(int a)
+{
+ switch (a) {
+ (int[3]){}; /* { dg-warning "statement will never be executed" } */
+ int h;
+ }
+}
--
2.12.2