From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id 7BD0038582BA for ; Fri, 8 Jul 2022 15:28:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BD0038582BA Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C5F5211689E; Fri, 8 Jul 2022 11:28:47 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id H1oPZs7RaVh0; Fri, 8 Jul 2022 11:28:47 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 891D11166B0; Fri, 8 Jul 2022 11:28:47 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 268FSb9B1212448 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 8 Jul 2022 12:28:39 -0300 From: Alexandre Oliva To: Richard Biener Cc: GCC Patches Subject: Re: [PATCH] Introduce hardbool attribute for C Organization: Free thinker, does not speak for AdaCore References: Errors-To: aoliva@lxoliva.fsfla.org Date: Fri, 08 Jul 2022 12:28:37 -0300 In-Reply-To: (Richard Biener's message of "Fri, 8 Jul 2022 08:58:34 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Fri, 08 Jul 2022 15:28:51 -0000 On Jul 8, 2022, Richard Biener wrote: > The documentation should probably be explicit about this case. Please consider, for purposes of review, the following incremental patchlet as if integrated with yesterday's submission. diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index a63a94158341a..a1dcd581dd8ad 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -8483,7 +8483,22 @@ followed by a mapping from @code{false} and @code{true} to typedef char __attribute__ ((__hardbool__ (0x5a))) hbool; hbool first = 0; /* False, stored as (char)0x5a. */ hbool second = !first; /* True, stored as ~(char)0x5a. */ -@end smallexample + +static hbool zeroinit; /* False, stored as (char)0x5a. */ +auto hbool uninit; /* Undefined, may trap. */ +@end smallexample + +When zero-initializing a variable or field of hardened boolean type +(presumably held in static storage) the implied zero initializer gets +converted to @code{_Bool}, and then to the hardened boolean type, so +that the initial value is the hardened representation for @code{false}. +Using that value is well defined. This is @emph{not} the case when +variables and fields of such types are uninitialized (presumably held in +automatic or dynamic storage): their values are indeterminate, and using +them invokes undefined behavior. Using them may trap or not, depending +on the bits held in the storage (re)used for the variable, if any, and +on optimizations the compiler may perform on the grounds that using +uninitialized values invokes undefined behavior. @item may_alias -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer Disinformation flourishes because many people care deeply about injustice but very few check the facts. Ask me about