From patchwork Tue Oct 29 21:53:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 287056 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9A8892C011C for ; Wed, 30 Oct 2013 08:54:22 +1100 (EST) 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=LjxhbNXwKQq+deU4g /97GPwKLNoXvG9HlbQVS8XdySAu5Z2BLjxOG//EbTPxdUBAwjjn6NhutJEdWTf89 IzyfzXJMY0sojz0b6OplfLbSAjFUkU5OQBl5L2uermptjO2TzQ8rrlMkkWr5ROGP +lIGGPqkR8H2h+YOan+RctL5po= 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=6HrKDkK0FMpN7JT9eKmnMqb jZ/c=; b=RKg6gh9fP4G2U9VwmH4w9EOWcopTvd5bAWKe1CuPuvf8hXqlWcPehGv /5a3c7xVVTlQggKK4f6gczNyj974o6hT3YLsgO8vWXafNJFB+E55wGKZy7PL3DYh GpGHf6X3dpQ5/X1lbf8tt9MVwrUW08v946nK/+1MqNiYwgLhutwc= Received: (qmail 1345 invoked by alias); 29 Oct 2013 21:54:15 -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 1328 invoked by uid 89); 29 Oct 2013 21:54:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f178.google.com Received: from mail-pd0-f178.google.com (HELO mail-pd0-f178.google.com) (209.85.192.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 29 Oct 2013 21:54:13 +0000 Received: by mail-pd0-f178.google.com with SMTP id x10so31657pdj.37 for ; Tue, 29 Oct 2013 14:54:11 -0700 (PDT) X-Received: by 10.66.154.1 with SMTP id vk1mr2545009pab.85.1383083650816; Tue, 29 Oct 2013 14:54:10 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr04-ext.fm.intel.com. [192.55.55.39]) by mx.google.com with ESMTPSA id wp8sm37045559pbc.26.2013.10.29.14.54.08 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 29 Oct 2013 14:54:10 -0700 (PDT) Date: Wed, 30 Oct 2013 01:53:23 +0400 From: Ilya Enkovich To: Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH, MPX, 2/X] Pointers Checker [5/25] Tree and gimple ifaces Message-ID: <20131029215323.GA46971@msticlxl57.ims.intel.com> References: <20131021122236.GE37888@msticlxl57.ims.intel.com> <20131024144329.GB39638@msticlxl57.ims.intel.com> <52700F0A.3010606@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <52700F0A.3010606@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On 29 Oct 13:39, Jeff Law wrote: > On 10/24/13 08:43, Ilya Enkovich wrote: > > > >+/* Return the number of arguments used by call statement GS. */ > >+ > >+static inline unsigned > >+gimple_call_num_nobnd_args (const_gimple gs) > >+{ > >+ unsigned num_args = gimple_call_num_args (gs); > >+ unsigned res = num_args; > >+ for (unsigned n = 0; n < num_args; n++) > >+ if (POINTER_BOUNDS_P (gimple_call_arg (gs, n))) > >+ res--; > >+ return res; > >+} > "number of arguments" seems wrong. Aren't you counting the number > of arguments without bounds? Damned copy-paste. > > > >+ > >+/* Nonzero if this type supposes bounds existence. */ > >+#define BOUNDED_TYPE_P(type) \ > >+ (TREE_CODE (type) == POINTER_TYPE \ > >+ || TREE_CODE (type) == REFERENCE_TYPE) > So how is this different than POINTER_TYPE_P? > > > If you really want BOUNDED_TYPE_P, perhaps define it in terms of > POINTER_TYPE_P? > > With that and the comment fix, this is fine. > > jeff I'd like to keep this macro. Currently it is equal to POINTER_TYPE_P but semantics is a little different. Below is a fixed version to be committed. Thanks! Ilya diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index e4b0f81..248dfea 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -539,11 +539,12 @@ dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags) static void dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags) { - tree t; + tree t, t2; t = gimple_return_retval (gs); + t2 = gimple_return_retbnd (gs); if (flags & TDF_RAW) - dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t); + dump_gimple_fmt (buffer, spc, flags, "%G <%T %T>", gs, t, t2); else { pp_string (buffer, "return"); @@ -552,6 +553,11 @@ dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags) pp_space (buffer); dump_generic_node (buffer, t, spc, flags, false); } + if (t2) + { + pp_string (buffer, ", "); + dump_generic_node (buffer, t2, spc, flags, false); + } pp_semicolon (buffer); } } diff --git a/gcc/gimple.c b/gcc/gimple.c index 3ddceb9..20f6010 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -174,7 +174,7 @@ gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode, gimple gimple_build_return (tree retval) { - gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 1); + gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 2); if (retval) gimple_return_set_retval (s, retval); return s; @@ -366,6 +366,26 @@ gimple_build_call_from_tree (tree t) } +/* Return index of INDEX's non bound argument of the call. */ + +unsigned +gimple_call_get_nobnd_arg_index (const_gimple gs, unsigned index) +{ + unsigned num_args = gimple_call_num_args (gs); + for (unsigned n = 0; n < num_args; n++) + { + if (POINTER_BOUNDS_P (gimple_call_arg (gs, n))) + continue; + else if (index) + index--; + else + return n; + } + + gcc_unreachable (); +} + + /* Extract the operands and code for expression EXPR into *SUBCODE_P, *OP1_P, *OP2_P and *OP3_P respectively. */ diff --git a/gcc/gimple.h b/gcc/gimple.h index fef64cd..c7ce394 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -919,6 +919,7 @@ extern tree get_initialized_tmp_var (tree, gimple_seq *, gimple_seq *); extern tree get_formal_tmp_var (tree, gimple_seq *); extern void declare_vars (tree, gimple, bool); extern void annotate_all_with_location (gimple_seq, location_t); +extern unsigned gimple_call_get_nobnd_arg_index (const_gimple, unsigned); /* Validation of GIMPLE expressions. Note that these predicates only check the basic form of the expression, they don't recurse to make sure that @@ -2414,6 +2415,32 @@ gimple_call_arg (const_gimple gs, unsigned index) } +/* Return the number of arguments used by call statement GS + ignoring bound ones. */ + +static inline unsigned +gimple_call_num_nobnd_args (const_gimple gs) +{ + unsigned num_args = gimple_call_num_args (gs); + unsigned res = num_args; + for (unsigned n = 0; n < num_args; n++) + if (POINTER_BOUNDS_P (gimple_call_arg (gs, n))) + res--; + return res; +} + + +/* Return INDEX's call argument ignoring bound ones. */ +static inline tree +gimple_call_nobnd_arg (const_gimple gs, unsigned index) +{ + /* No bound args may exist if pointers checker is off. */ + if (!flag_check_pointer_bounds) + return gimple_call_arg (gs, index); + return gimple_call_arg (gs, gimple_call_get_nobnd_arg_index (gs, index)); +} + + /* Return a pointer to the argument at position INDEX for call statement GS. */ @@ -5220,6 +5247,26 @@ gimple_return_set_retval (gimple gs, tree retval) } +/* Return the return bounds for GIMPLE_RETURN GS. */ + +static inline tree +gimple_return_retbnd (const_gimple gs) +{ + GIMPLE_CHECK (gs, GIMPLE_RETURN); + return gimple_op (gs, 1); +} + + +/* Set RETVAL to be the return bounds for GIMPLE_RETURN GS. */ + +static inline void +gimple_return_set_retbnd (gimple gs, tree retval) +{ + GIMPLE_CHECK (gs, GIMPLE_RETURN); + gimple_set_op (gs, 1, retval); +} + + /* Returns true when the gimple statement STMT is any of the OpenMP types. */ #define CASE_GIMPLE_OMP \ diff --git a/gcc/tree-core.h b/gcc/tree-core.h index ea110bc..638b3ab 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -448,6 +448,8 @@ enum tree_index { TI_FILEPTR_TYPE, TI_POINTER_SIZED_TYPE, + TI_POINTER_BOUNDS_TYPE, + TI_DFLOAT32_TYPE, TI_DFLOAT64_TYPE, TI_DFLOAT128_TYPE, diff --git a/gcc/tree.c b/gcc/tree.c index 0a42109..de08aea 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -9765,6 +9765,8 @@ build_common_tree_nodes (bool signed_char, bool short_double) void_type_node = make_node (VOID_TYPE); layout_type (void_type_node); + pointer_bounds_type_node = targetm.chkp_bound_type (); + /* We are not going to have real types in C with less than byte alignment, so we might as well not have any types that claim to have it. */ TYPE_ALIGN (void_type_node) = BITS_PER_UNIT; diff --git a/gcc/tree.h b/gcc/tree.h index ab1d0ab..3fe751e 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -546,6 +546,17 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, #define POINTER_BOUNDS_TYPE_P(NODE) \ (TREE_CODE (NODE) == POINTER_BOUNDS_TYPE) +/* Nonzero if this node has a pointer bounds type. */ +#define POINTER_BOUNDS_P(NODE) \ + (POINTER_BOUNDS_TYPE_P (TREE_TYPE (NODE))) + +/* Nonzero if this type supposes bounds existence. */ +#define BOUNDED_TYPE_P(type) (POINTER_TYPE_P (type)) + +/* Nonzero for objects with bounded type. */ +#define BOUNDED_P(node) \ + BOUNDED_TYPE_P (TREE_TYPE (node)) + /* Nonzero if this type is the (possibly qualified) void type. */ #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE) @@ -3197,6 +3208,8 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i, #define complex_double_type_node global_trees[TI_COMPLEX_DOUBLE_TYPE] #define complex_long_double_type_node global_trees[TI_COMPLEX_LONG_DOUBLE_TYPE] +#define pointer_bounds_type_node global_trees[TI_POINTER_BOUNDS_TYPE] + #define void_type_node global_trees[TI_VOID_TYPE] /* The C type `void *'. */ #define ptr_type_node global_trees[TI_PTR_TYPE]