From patchwork Fri May 26 11:05:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 767358 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wZ3G14gL9z9s8V for ; Fri, 26 May 2017 21:05:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="W+Lw3AiH"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=gHXT2pFNaPpdzKPTrk/2Yuv3UmAikHlfQ3yQKtj3qyAckPnPYX xIV9MnlzeKY65EeEcrlf0DK5IRRC5QmdeKHzP+Wk+T14aVUwSx9Rf00Ra5nWsGib cCwwp1ZLonxRr9LDeXiplyVrHz4EyGtGJlD9ZS2xh4mKInRueFOn2hvek= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=xsqfVzvwCAjILaBJLTaB9Kf/Ijc=; b=W+Lw3AiHQSyZ/emKnqwh CPyhwSAY0Kk53GVhnOEXo1Ac4GwIo8THbcQnMPrADBl3ieSSPg/KU8iUBBZAVdGj EFrOf6eTutPgS7rfXmFS1l/jjkEaFTZelX1d8/J23OT3Nu7U4hQO4OUHHTorvntA tsMauIfF03ZmtshAlVYFq6Q= Received: (qmail 59320 invoked by alias); 26 May 2017 11:05:33 -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 59100 invoked by uid 89); 26 May 2017 11:05:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 May 2017 11:05:30 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 64086AAB9; Fri, 26 May 2017 11:05:32 +0000 (UTC) To: GCC Patches Cc: Jakub Jelinek From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879). Message-ID: <08849f53-06b3-ab85-d524-7d291d9ab509@suse.cz> Date: Fri, 26 May 2017 13:05:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 X-IsSubscribed: yes Hello. Unfortunately I guarded use-after-scope to track live switch variables just to BIND_EXPR. However the bind expression can be included in a STATEMENT_LIST. That enables proper tracking and fixes the test added. Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin From a7f63e228118b3f256d9e774fdeeb8c85c0da437 Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 25 May 2017 17:53:06 +0200 Subject: [PATCH] Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST (PR sanitizer/80879). gcc/ChangeLog: 2017-05-25 Martin Liska * gimplify.c (gimplify_switch_expr): Initialize live_switch_vars for SWITCH_BODY == STATEMENT_LIST. gcc/testsuite/ChangeLog: 2017-05-25 Martin Liska * gcc.dg/asan/use-after-scope-switch-4.c: New test. --- gcc/gimplify.c | 3 +- .../gcc.dg/asan/use-after-scope-switch-4.c | 35 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 455a6993e15..0983ebef298 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2279,7 +2279,8 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) /* 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) + tree_code body_type = TREE_CODE (SWITCH_BODY (switch_expr)); + if (body_type == BIND_EXPR || body_type == STATEMENT_LIST) gimplify_ctxp->live_switch_vars = new hash_set (4); else gimplify_ctxp->live_switch_vars = NULL; diff --git a/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c new file mode 100644 index 00000000000..290a920633b --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/use-after-scope-switch-4.c @@ -0,0 +1,35 @@ +// { dg-do run } +// { dg-additional-options "-fdump-tree-gimple" } + +int *ptr; + +struct a +{ + int c; +}; + +int main(int argc, char **argv) +{ + struct a e; + e.c = 2; + int x = 0; + + for (;;) + switch (e.c) + case 3: + { + int resxxx; + case 2: + ptr = &resxxx; + *ptr = 123; + + if (x) + return 0; + else + x = 1; + } + + return 1; +} + +/* { dg-final { scan-tree-dump-times "ASAN_MARK \\(UNPOISON, &resxxx, \[0-9\]\\);" 2 "gimple" } } */ -- 2.12.2