From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id E06123857C75 for ; Wed, 6 Jan 2021 09:21:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E06123857C75 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rguenther@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0776AAD19; Wed, 6 Jan 2021 09:21:08 +0000 (UTC) Date: Wed, 6 Jan 2021 10:21:07 +0100 (CET) From: Richard Biener Sender: rguenther@ryzen.fritz.box To: Joseph Myers cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] add g_nonstandard_bool attribute for GIMPLE FE use In-Reply-To: Message-ID: References: <905fd139-f616-b2f8-efe6-c6e0eed61e15@gmail.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jan 2021 09:21:10 -0000 On Tue, 5 Jan 2021, Joseph Myers wrote: > On Tue, 5 Jan 2021, Richard Biener wrote: > > > would maybe result in a surprising result. One alternative > > would be to make the attribute have the signedness specified as well > > (C doesn't accept 'unsigned _Bool' or 'signed _Bool') or > > simply name the attribute "signed_bool_precision". I guess the bool case > > is really special compared to the desire to eventually allow > > declaring of a 3 bit precision signed/unsigned integer type. > > > > Allowing 'signed _Bool' with -fgimple might be another option > > of course. > > Something that makes clear it's a signed boolean type with the given > precision seems a good idea (I'd have assumed a nonstandard boolean type > with a given precision was unsigned). OK, I've used signed_bool_precision, re-bootstrapped and tested on x86_64-unknown-linux-gnu and pushed as below. Richard. >From c9ee9c1e3553247c776f33eb0fe0aadee094a192 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 11 Dec 2020 09:50:59 +0100 Subject: [PATCH] add signed_bool_precision attribute for GIMPLE FE use To: gcc-patches@gcc.gnu.org This adds __attribute__((signed_bool_precision(precision))) to be able to construct nonstandard boolean types which for the included testcase is needed to simulate Ada and LTO interaction (Ada uses a 8 bit precision boolean_type_node). This will also be useful for vector unit testcases where we need to produce vector types with non-standard precision signed boolean type components. 2021-01-06 Richard Biener PR tree-optimization/95582 gcc/c-family/ * c-attribs.c (c_common_attribute_table): Add entry for signed_bool_precision. (handle_signed_bool_precision_attribute): New. gcc/testsuite/ * gcc.dg/pr95582.c: New testcase. --- gcc/c-family/c-attribs.c | 41 ++++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr95582.c | 19 ++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr95582.c diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index ef7cec9b2e8..84ec86b2091 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -161,6 +161,8 @@ static tree handle_copy_attribute (tree *, tree, tree, int, bool *); static tree handle_nsobject_attribute (tree *, tree, tree, int, bool *); static tree handle_objc_root_class_attribute (tree *, tree, tree, int, bool *); static tree handle_objc_nullability_attribute (tree *, tree, tree, int, bool *); +static tree handle_signed_bool_precision_attribute (tree *, tree, tree, int, + bool *); /* Helper to define attribute exclusions. */ #define ATTR_EXCL(name, function, type, variable) \ @@ -274,6 +276,8 @@ const struct attribute_spec c_common_attribute_table[] = { /* { name, min_len, max_len, decl_req, type_req, fn_type_req, affects_type_identity, handler, exclude } */ + { "signed_bool_precision", 1, 1, false, true, false, true, + handle_signed_bool_precision_attribute, NULL }, { "packed", 0, 0, false, false, false, false, handle_packed_attribute, attr_aligned_exclusions }, @@ -894,6 +898,43 @@ validate_attr_arg (tree node[2], tree name, tree newarg) /* Attribute handlers common to C front ends. */ +/* Handle a "signed_bool_precision" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_signed_bool_precision_attribute (tree *node, tree name, tree args, + int, bool *no_add_attrs) +{ + *no_add_attrs = true; + if (!flag_gimple) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + return NULL_TREE; + } + + if (!TYPE_P (*node) || TREE_CODE (*node) != BOOLEAN_TYPE) + { + warning (OPT_Wattributes, "%qE attribute only supported on " + "boolean types", name); + return NULL_TREE; + } + + unsigned HOST_WIDE_INT prec = HOST_WIDE_INT_M1U; + if (tree_fits_uhwi_p (TREE_VALUE (args))) + prec = tree_to_uhwi (TREE_VALUE (args)); + if (prec > MAX_FIXED_MODE_SIZE) + { + warning (OPT_Wattributes, "%qE attribute with unsupported boolean " + "precision", name); + return NULL_TREE; + } + + tree new_type = build_nonstandard_boolean_type (prec); + *node = lang_hooks.types.reconstruct_complex_type (*node, new_type); + + return NULL_TREE; +} + /* Handle a "packed" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/testsuite/gcc.dg/pr95582.c b/gcc/testsuite/gcc.dg/pr95582.c new file mode 100644 index 00000000000..cc2ab46ec95 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr95582.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O3" } */ + +typedef _Bool bool8 __attribute__((signed_bool_precision(8))); + +bool8 data[16]; + +void __GIMPLE(ssa) foo(int f) +{ + _Bool t; + bool8 tp; + +__BB(2): + t_2 = f_1(D) != 0; + tp_3 = (bool8) t_2; + data[0] = tp_3; + data[1] = tp_3; + return; +} -- 2.26.2