From patchwork Mon Jan 26 16:45:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 432944 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 40085140188 for ; Tue, 27 Jan 2015 03:57:34 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=PcOx28/S1tsmTjiwJCrDRBJ/Vq+gE6Ya+0+8YcGzt2NzaJpuTLt6q QSJPWPlrj3vgyHIqi9k47maKgl2RSMcKazv17/jo84MRgbMqAYtR5WxUSM00XWq1 5s+E5ytgisA7JtUIf5linPJmpVrTNbO7J54F2mJ99K9DWVBQTbixW4= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=kR96J96WqYOXV+CK4aFJv0X17G8=; b=ingjypxNx9QiHgN4H0Cj /vjmeLYQvu0hNc1waM8m69ZFTwthRTdyClkWuZ1Smntwu1ibtVkdNlTxJ6SsCZyM Wv0XElMo/tIhHoKlOWHzZeND+rdet50WuAAw+dO+LKIVgm//iAQFbZ5+BK7h7reA m5p7ziPSFtKknk1ZzR+zbS4= Received: (qmail 27261 invoked by alias); 26 Jan 2015 16:46:49 -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 27128 invoked by uid 89); 26 Jan 2015 16:46:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ig0-f176.google.com Received: from mail-ig0-f176.google.com (HELO mail-ig0-f176.google.com) (209.85.213.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 26 Jan 2015 16:46:01 +0000 Received: by mail-ig0-f176.google.com with SMTP id hl2so9354539igb.3 for ; Mon, 26 Jan 2015 08:45:59 -0800 (PST) X-Received: by 10.50.66.131 with SMTP id f3mr17177294igt.17.1422290758891; Mon, 26 Jan 2015 08:45:58 -0800 (PST) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id n17sm5973601igi.2.2015.01.26.08.45.57 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Jan 2015 08:45:58 -0800 (PST) Date: Mon, 26 Jan 2015 19:45:48 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, CHKP] Fix bounds return check for calls Message-ID: <20150126164548.GA47190@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, Currently chkp_call_returns_bounds_p works incorrectly for bounds narrowing. Also it doesn't reflect recent changes in calls instrumentation. This patch fixes the problem. Bootstrapped and checked on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Ilya --- 2015-01-26 Ilya Enkovich * tree-chkp.c (chkp_call_returns_bounds_p): Fix handling of bounds narrowing, already instrumented calls and calls to not instrumentable functions. 2015-01-26 Ilya Enkovich * gcc.target/i386/chkp-narrow-bounds.c: New. diff --git a/gcc/testsuite/gcc.target/i386/chkp-narrow-bounds.c b/gcc/testsuite/gcc.target/i386/chkp-narrow-bounds.c new file mode 100644 index 0000000..28bc622 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/chkp-narrow-bounds.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target mpx } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx -O2 -fdump-tree-chkp" } */ +/* { dg-final { scan-tree-dump "bndcl" "chkp" } } */ +/* { dg-final { scan-tree-dump "bndcu" "chkp" } } */ +/* { dg-final { cleanup-tree-dump "chkp" } } */ + +int +test (int *p) +{ + int *p1 = __bnd_narrow_ptr_bounds (p - 10, p, sizeof (int) * 20); + return p1[10]; +} diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index e7649ef..b0a3a15 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -2113,13 +2113,19 @@ chkp_call_returns_bounds_p (gcall *call) if (gimple_call_internal_p (call)) return false; + if (gimple_call_builtin_p (call, BUILT_IN_CHKP_NARROW_PTR_BOUNDS) + || chkp_gimple_call_builtin_p (call, BUILT_IN_CHKP_NARROW)) + return true; + + if (gimple_call_with_bounds_p (call)) + return true; + tree fndecl = gimple_call_fndecl (call); if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD) return false; - if (fndecl - && lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (fndecl))) + if (fndecl && !chkp_instrumentable_p (fndecl)) return false; if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)