From patchwork Thu Jul 2 21:43:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1321948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49yWmr2Ml5z9sQt for ; Fri, 3 Jul 2020 07:43:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99BF53851C1B; Thu, 2 Jul 2020 21:43:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 7DD98385BF81 for ; Thu, 2 Jul 2020 21:43:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7DD98385BF81 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: sG9a/N2MyeKeqJMhey+cUiGnQdTzlmZBRYJJ2VUghd2Jprn/6f+K/sEmDw1anjfbhmFKTXmtof QF3TU5c0L+f+pQZBkhatzkedX0cBDrZFSHfJt++tZZ1SyM2MiJxZyZLpMQjqJ06epfA8gNWuZQ 2J+EU2s+aW4nHBrCZauZqOuazPgmB9N7zmbs+k9NSI7MGUURPHyDrZMqEt1rMAL2ENdzwfX4cX j4QsZZmP7p5TZlyBLB9F1AywR/ZNYKXpmeO3EKpJ0Jwp0KnDueWKsOafYg6JP0MaFpgqHMI8FC 7vo= X-IronPort-AV: E=Sophos;i="5.75,305,1589270400"; d="scan'208";a="50562107" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 02 Jul 2020 13:43:16 -0800 IronPort-SDR: 5uJddTHuEkxecQAyj3E1U9rOZc7ss0suML9PEexsFwp329MaQ7MeFZoxqNFk8dvY8i3ruC26gJ vX21bLTRmMKgDUgA5IadTLHdDXLDHVpJZeiYzYeoO1Ee/yPBb3/ysyVJocg3ZHGXB4hvkm4K7k kn1phwkpHFGVk2WRxWL9GUFkX5kcneU1TQ0QQLHbcCPFDeq4926LYY8O8Ks/otonltkO+ama3F yYFNvwdXsNDKnYE1OqelbCX4SxB3qW4wZY3VYOs4pgHH2o4KZG0iM9aUZC55oGtguGBdjux6Tx Bf0= Date: Thu, 2 Jul 2020 21:43:10 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: c: Add C2X BOOL_MAX and BOOL_WIDTH to limits.h Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-3134.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" C2X adds BOOL_MAX and BOOL_WIDTH macros to . As GCC only supports values 0 and 1 for _Bool (regardless of the number of bits in the representation, other bits are padding bits and if any of them are nonzero, the representation is a trap representation), the values of those macros can just be hardcoded directly in rather than needing corresponding predefined macros. Bootstrapped with no regressions on x86_64-pc-linux-gnu. OK to commit? gcc/ 2020-07-02 Joseph Myers * glimits.h [__STDC_VERSION__ > 201710L] (BOOL_MAX, BOOL_WIDTH): New macros. gcc/testsuite/ 2020-07-02 Joseph Myers * gcc.dg/c11-bool-limits-1.c, gcc.dg/c2x-bool-limits-1.c: New tests. diff --git a/gcc/glimits.h b/gcc/glimits.h index a37f496ef1b..50927510677 100644 --- a/gcc/glimits.h +++ b/gcc/glimits.h @@ -150,4 +150,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see # define ULLONG_WIDTH __LONG_LONG_WIDTH__ #endif +#if defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L +/* C2X width and limit of _Bool. */ +# undef BOOL_MAX +# define BOOL_MAX 1 +# undef BOOL_WIDTH +# define BOOL_WIDTH 1 +#endif + #endif /* _LIMITS_H___ */ diff --git a/gcc/testsuite/gcc.dg/c11-bool-limits-1.c b/gcc/testsuite/gcc.dg/c11-bool-limits-1.c new file mode 100644 index 00000000000..9ca29be4d72 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-bool-limits-1.c @@ -0,0 +1,13 @@ +/* Test limits for _Bool not in in C11. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11" } */ + +#include + +#ifdef BOOL_MAX +# error "unexpected BOOL_MAX" +#endif + +#ifdef BOOL_WIDTH +# error "unexpected BOOL_WIDTH" +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-bool-limits-1.c b/gcc/testsuite/gcc.dg/c2x-bool-limits-1.c new file mode 100644 index 00000000000..d32b4ef59ed --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-bool-limits-1.c @@ -0,0 +1,19 @@ +/* Test limits for _Bool in in C2x. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x" } */ + +#include + +#ifndef BOOL_MAX +# error "missing BOOL_MAX" +#endif + +#ifndef BOOL_WIDTH +# error "missing BOOL_WIDTH" +#endif + +/* In principle _Bool can support values wider than 1 bit, stored via + type punning, but this is not supported by GCC. */ + +_Static_assert (BOOL_MAX == 1, "bad BOOL_MAX"); +_Static_assert (BOOL_WIDTH == 1, "bad BOOL_WIDTH");