From patchwork Thu Nov 10 11:02:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 81630 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp661206qge; Thu, 10 Nov 2016 03:03:33 -0800 (PST) X-Received: by 10.98.204.72 with SMTP id a69mr9177921pfg.76.1478775813460; Thu, 10 Nov 2016 03:03:33 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l3si4232210pgn.2.2016.11.10.03.03.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Nov 2016 03:03:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-440940-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-440940-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440940-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=rftSXMzJwxwdjlAn7 DtqLcpH0qlxXxBvaQot3Fl9DqR5MNFIj++uDihDad+VJgqhY0SI+3yhZOox1J8is 3ACwn7WjwrMFB4WHr654ByMXjH45jzksQyFCqQHosoAGcGcCoNzUIPABqSJ+KdjQ 6T06QvVpQL8XIHzA57PZO3II3Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=q0XRyGEwoO4XKV8h9guliVj Ipkc=; b=GiBDZ1LUuvT6sGK+Sf6JdKSFvQWUQtq3+/udz9wD74ooCcxghbdIqTo ThcsQZJlNSpvSXZ9ARJU6Dq5DcitlLj/Pg5kqRgQcpdErWUamVD38H2DsoEi4MHf NVTeYoBa1DA5iu6sLj0iHyvUL2wZDEBE66aivXu3lm77dter3u+4= Received: (qmail 119487 invoked by alias); 10 Nov 2016 11:02:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 119424 invoked by uid 89); 10 Nov 2016 11:02:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=gimple_seq, sk:gimplif, *expr_p, compound X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Nov 2016 11:02:48 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 27B03ABFB; Thu, 10 Nov 2016 11:02:46 +0000 (UTC) Subject: Re: [PATCH] Remove unneeded gcc_assert in gimplifier (PR sanitizer/78270) To: Jakub Jelinek References: <475cb650-8a3d-8395-9f93-da12e8e841a1@suse.cz> <20161109132900.GA3541@tucnak.redhat.com> <6339c6f2-fa0e-d63e-fe2a-f7ca9d7ae924@suse.cz> Cc: GCC Patches From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <4a129694-400b-9899-de79-4f0f07ed6311@suse.cz> Date: Thu, 10 Nov 2016 12:02:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <6339c6f2-fa0e-d63e-fe2a-f7ca9d7ae924@suse.cz> X-IsSubscribed: yes On 11/09/2016 02:47 PM, Martin Liška wrote: > On 11/09/2016 02:29 PM, Jakub Jelinek wrote: >> On Wed, Nov 09, 2016 at 02:16:45PM +0100, Martin Liška wrote: >>> As shown in the attached test-case, the assert cannot always be true. >>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. >>> >>> Ready to be installed? >>> Martin >> >>> >From b55459461f3f7396a094be6801082715ddb4b30d Mon Sep 17 00:00:00 2001 >>> From: marxin >>> Date: Wed, 9 Nov 2016 11:52:00 +0100 >>> Subject: [PATCH] Remove unneeded gcc_assert in gimplifier (PR sanitizer/78270) >>> >>> gcc/ChangeLog: >>> >>> 2016-11-09 Martin Liska >>> >>> PR sanitizer/78270 >>> * gimplify.c (gimplify_switch_expr): >> >> No description on what you've changed. >> >> That said, I'm not 100% sure it is the right fix. >> As the testcase shows, for switch without GIMPLE_BIND wrapping the body >> we can have variables that are in scope from the switch onwards. >> I bet we could also have variables that go out of scope, say if in the >> compound literal's initializer there is ({ ... }) that declares variables. >> I doubt you can have a valid case/default label in those though, so >> perhaps it would be simpler not to create live_switch_vars at all >> if SWITCH_BODY is not a BIND_EXPR? > > I like the approach you introduced! I'll re-trigger regression tests and > send a newer version of patch. > > Martin Sending the patch. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin > >> >> Jakub >> > >From fb4b852a17656309e6acfb8da97cf9bce4b3b176 Mon Sep 17 00:00:00 2001 From: marxin 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 * gcc.dg/asan/pr78269.c: New test. gcc/ChangeLog: 2016-11-09 Martin Liska * 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 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index d392450..da60c05 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2241,7 +2241,7 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) { vec labels; vec saved_labels; - hash_set *saved_live_switch_vars; + hash_set *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 (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 (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/gcc.dg/asan/pr78269.c b/gcc/testsuite/gcc.dg/asan/pr78269.c new file mode 100644 index 0000000..55840b0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr78269.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){}; +} -- 2.10.1