From patchwork Thu Mar 23 14:18:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivchenko X-Patchwork-Id: 742678 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 3vppbK2nJvz9s0g for ; Fri, 24 Mar 2017 01:19:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CEqmSyEs"; 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 :mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; q=dns; s=default; b=nUBgm+Phbpd0OYR6 oyWLe+qzaBdp/uVpwgRqM55cBrT507MEYgcDty7qDofE4c4MX3BSMguomwpLxmVV RVatiW0Mt4VCsveJxA0R9/08feZRVeKiuww3cbAPdI5RkWiRO75cIy0BVmhvWYF/ PmiSFgkRGMWRq/nu+8wjSyPXInE= 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 :mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; s=default; bh=+pukGi7qBBZh3kbvG5y1rS aYqWg=; b=CEqmSyEsAtPkm+V62Fb2W8qXlAu6L7lNNaLZgRAN39x8B9x8MSa9XS ITO7OMEM4dkSnRMiakwdFjECfS5XFlHFafbQ1YJ6SzfQrmVfH5PNteIs0FKxbS3+ g7/jna8vmMOJamfyzhyZf4VILEDmrOkZgglMzXHxCMx6bGI90CkZ8= Received: (qmail 92791 invoked by alias); 23 Mar 2017 14:19:30 -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 92772 invoked by uid 89); 23 Mar 2017 14:19:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2983, unsafe, business X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-qt0-f182.google.com Received: from mail-qt0-f182.google.com (HELO mail-qt0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Mar 2017 14:19:28 +0000 Received: by mail-qt0-f182.google.com with SMTP id i34so176648144qtc.0; Thu, 23 Mar 2017 07:19:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=9JRVlDywP5Pn8SKP4c1TzxzuyTsT7OD0HVB1V4d/iIE=; b=ayAYnC0aOLAGpJq3AqpTikc2GWmqcJO5mI14Z9A6lQ0ZNCZVjfekeQQkdnHgvhBZnK qjYDeC9VGKdVvtb1Vpwo9ifM1EvvFYRm4/4+cvKregATRDUVCh1Ay2f+R9XqOdILbxUK eswZ2T+CCvjjndm3KKY3LglTRMATfMWSzvQk5ZWCR6idWiBAysNFQKwo/MYSqcakd6zk 1STRWt85S6CTzpFDy5oC4Vsx20EB4ws+8l84tmjFeFP+g4r6j/HX1rwGvSP6aa5UUrDz UENEWAm2oJN87km80e5mFhHcLj4a+Vjl2t+iCmcXqPgX2bPwLfyV53QTwAWNdHOEnJWX o9/A== X-Gm-Message-State: AFeK/H36ZO3FgKdnfWt5t7yEJLBfnunOp/OKs2dpQCIhRLnxl9BY7JVOQIAFGK+1I8Sz3EAA7BE3uQVdyHUs8Q== X-Received: by 10.200.50.147 with SMTP id z19mr2477949qta.256.1490278767689; Thu, 23 Mar 2017 07:19:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.55.7 with HTTP; Thu, 23 Mar 2017 07:18:47 -0700 (PDT) From: Alexander Ivchenko Date: Thu, 23 Mar 2017 15:18:47 +0100 Message-ID: Subject: [CHKP] Fix for PR79990 To: Ilya Enkovich , marxin@gcc.gnu.org, GCC Patches X-IsSubscribed: yes Hi, The patch below attempts to fix the PR. I checked that it did not break any of mpx.exp tests, but I did not run the full testing yet. Would like to know whether this approach is generally correct or not. The issue is that we have the hard reg vector variable: typedef int U __attribute__ ((vector_size (16))); register U u asm("xmm0"); and chkp tries to instrument access to it: return u[i]; by doing that: __bound_tmp.0_4 = __builtin_ia32_bndmk (&u, 16); However, you cannot take an address of a register variable (in fact if you do that, the compiler will give you "address of register variable ā€˜uā€™ requested" error), so expand, sensibly, gives an ICE on on &u here. I believe that if there is no pointers, pointer bounds checker shouldn't get involved into that business. What do you think? regards, Alexander diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 75caf83..e39ec9a 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -3383,6 +3383,7 @@ chkp_parse_array_and_component_ref (tree node, tree *ptr, tree comp_to_narrow = NULL_TREE; tree last_comp = NULL_TREE; bool array_ref_found = false; + bool is_register_var = false; tree *nodes; tree var; int len; @@ -3440,6 +3441,9 @@ chkp_parse_array_and_component_ref (tree node, tree *ptr, || TREE_CODE (var) == STRING_CST || TREE_CODE (var) == SSA_NAME); + if (VAR_P (var) && DECL_HARD_REGISTER (var)) + is_register_var = true; + *ptr = chkp_build_addr_expr (var); } @@ -3455,7 +3459,11 @@ chkp_parse_array_and_component_ref (tree node, tree *ptr, if (TREE_CODE (var) == ARRAY_REF) { - *safe = false; + // Mark it as unsafe, unless the array being accessed + // has been explicitly placed on a register: in this + // case we cannot take a pointer of this variable, + // so we don't instrument the access. + *safe = is_register_var; array_ref_found = true; if (flag_chkp_narrow_bounds && !flag_chkp_narrow_to_innermost_arrray @@ -4001,6 +4009,19 @@ chkp_process_stmt (gimple_stmt_iterator *iter, tree node, bool bitfield; tree elt; + { + // We don't instrument accesses to arrays that + // are explicitely assigned to hard registers. + HOST_WIDE_INT bitsize, bitpos; + tree base, offset; + machine_mode mode; + int unsignedp, reversep, volatilep = 0; + base = get_inner_reference (node, &bitsize, &bitpos, &offset, &mode, + &unsignedp, &reversep, &volatilep); + if (VAR_P (base) && DECL_HARD_REGISTER (base)) + safe = true; + } + if (safe) { /* We are not going to generate any checks, so do not diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr79990.c b/gcc/testsuite/gcc.target/i386/mpx/pr79990.c new file mode 100644 index 0000000..a27734d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/pr79990.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */ + +typedef int U __attribute__ ((vector_size (16))); + +int +foo (int i) +{ +#if __SSE2__ + register +#endif + U u +#if __SSE2__ + asm ("xmm0") +#endif + ; + return u[i]; +}