Re: [PATCH] Introduce hardbool attribute for C

2023-06-29 Thread Qing Zhao via Gcc-patches
Hi, ALexandre, Thank you for the explanation. I am now clear with the interaction between hardbool and -ftrivial-auto-var-init, and also agree that clarifying the documentation on their interaction is good enough. Qing > On Jun 29, 2023, at 6:30 AM, Alexandre Oliva wrote: > > On Jun 28, 2023

Re: [PATCH] Introduce hardbool attribute for C

2023-06-29 Thread Alexandre Oliva via Gcc-patches
On Jun 28, 2023, Qing Zhao wrote: > In summary, Ada’s Boolean variables (whether it’s hardened or not) are > represented as > enumeration types in GNU IR. Not quite. Only boolean types with representation clauses are. Those without (such as Standard.Boolean) are BOOLEAN_TYPEs. But those witho

Re: [PATCH] Introduce hardbool attribute for C

2023-06-28 Thread Qing Zhao via Gcc-patches
> On Jun 28, 2023, at 3:26 AM, Alexandre Oliva wrote: > > I'd probably have arranged for the front-end to create the initializer > value, because expansion time is too late to figure it out: we may not > even have the front-end at hand any more, in case of lto compilation. >>>

Re: [PATCH] Introduce hardbool attribute for C

2023-06-28 Thread Alexandre Oliva via Gcc-patches
On Jun 26, 2023, Qing Zhao wrote: >>> For hardbool variables, what 0x00 represents if it’s not false or true >>> value? >> >> It depends on how hardbool is parameterized. One may pick 0x00 or 0xFE >> as the representations for true or false, or neither, in which case the >> trivial initializer

Re: [PATCH] Introduce hardbool attribute for C

2023-06-26 Thread Qing Zhao via Gcc-patches
Hi, Alexandre, > On Jun 23, 2023, at 10:38 PM, Alexandre Oliva wrote: > >> For normal Boolean variables, 0x00 is false, this is a reasonable init >> value with zero-initialization. > > *nod*. I was surprised by zero initialization of (non-hardened) > booleans even when pattern is requested, bu

Re: [PATCH] Introduce hardbool attribute for C

2023-06-23 Thread Alexandre Oliva via Gcc-patches
On Jun 16, 2023, Alexandre Oliva wrote: > On Aug 9, 2022, Alexandre Oliva wrote: >> Ping? > Ping? Refreshed, added setting of ENUM_UNDERLYING_TYPE, retested on > x86_64-linux-gnu (also on gcc-13). Here's a consolidated patch incorporating the doc and test patchlets sent out in response to Qi

Re: [PATCH] Introduce hardbool attribute for C

2023-06-23 Thread Alexandre Oliva via Gcc-patches
On Jun 22, 2023, Bernhard Reutner-Fischer wrote: > On Wed, 21 Jun 2023 22:08:55 -0300 > Alexandre Oliva wrote: >> Thanks for the test. >> >> Did you mean for me to incorporate it into the patch, or do you mean to >> contribute it separately, if the feature happens to be accepted? > These were

Re: [PATCH] Introduce hardbool attribute for C

2023-06-23 Thread Alexandre Oliva via Gcc-patches
On Jun 23, 2023, Qing Zhao via Gcc-patches wrote: > -ftrivial-auto-var-init has been in GCC since GCC12. *nod*. IIRC I started designing hardbool in GCC10, but the first complete implementation was for GCC11. > The decision to use 0x00 for zero-initiation, 0xfe for pattern-initiation > has b

Re: [PATCH] Introduce hardbool attribute for C

2023-06-23 Thread Qing Zhao via Gcc-patches
> On Jun 21, 2023, at 10:35 PM, Alexandre Oliva wrote: > > On Jun 21, 2023, Qing Zhao wrote: > >> I see that you have testing case to check the above built_in_trap call >> is generated by FE. >> Do you have a testing case to check the trap is happening at runtime? > > I have written such te

Re: [PATCH] Introduce hardbool attribute for C

2023-06-22 Thread Bernhard Reutner-Fischer via Gcc-patches
On Wed, 21 Jun 2023 22:08:55 -0300 Alexandre Oliva wrote: > Thanks for the test. > > Did you mean for me to incorporate it into the patch, or do you mean to > contribute it separately, if the feature happens to be accepted? These were your tests that i quoted but i or my MUA botched to add one

Re: [PATCH] Introduce hardbool attribute for C

2023-06-21 Thread Alexandre Oliva via Gcc-patches
On Jun 21, 2023, Qing Zhao wrote: > I see that you have testing case to check the above built_in_trap call > is generated by FE. > Do you have a testing case to check the trap is happening at runtime? I have written such tests, using type-punning, but I don't think our testing infrastructure co

Re: [PATCH] Introduce hardbool attribute for C

2023-06-21 Thread Alexandre Oliva via Gcc-patches
Thanks for the test. Did you mean for me to incorporate it into the patch, or do you mean to contribute it separately, if the feature happens to be accepted? On Jun 19, 2023, Bernhard Reutner-Fischer wrote: > I don't see explicit tests with _Complex nor __complex__. Would we > want to check the

Re: [PATCH] Introduce hardbool attribute for C

2023-06-21 Thread Qing Zhao via Gcc-patches
Hi, Alexandre, > > diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc > index 22e240a3c2a55..f9cc609b54d94 100644 > --- a/gcc/c/c-typeck.cc > +++ b/gcc/c/c-typeck.cc > @@ -2226,6 +2226,35 @@ convert_lvalue_to_rvalue (location_t loc, struct > c_expr exp, > exp.value = convert (build_qualified

Re: [PATCH] Introduce hardbool attribute for C

2023-06-19 Thread Bernhard Reutner-Fischer via Gcc-patches
On 16 June 2023 07:35:27 CEST, Alexandre Oliva via Gcc-patches wrote: index 0..634feaed4deef --- /dev/null +++ b/gcc/testsuite/gcc.dg/hardbool-err.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +typedef _Bool __attribute__ ((__hardbool__)) +hbbl; /* { dg-error

Re: [PATCH] Introduce hardbool attribute for C

2023-06-16 Thread Alexandre Oliva via Gcc-patches
On Jun 16, 2023, Thomas Koenig wrote: > So, such a type would be incompatible with vanilla LOGICAL variables > and with C interop logical variables. Yeah, it would. It's something else, and if you choose to use such a type in an interface, it would need to be handled as such. Presumably, absen

Re: [PATCH] Introduce hardbool attribute for C

2023-06-15 Thread Thomas Koenig via Gcc-patches
Hi Alexandre, On Apr 6, 2023, Bernhard Reutner-Fischer wrote: 29 For C_BOOL, the internal representation of .TRUE._C_BOOL and .FALSE._C_BOOL shall be the same as those of 30 the C values (_Bool)1 and (_Bool)0 respectively. I'm not changing any of the standard types, FWIW. The proposed ext

Re: [PATCH] Introduce hardbool attribute for C

2023-06-15 Thread Alexandre Oliva via Gcc-patches
On Aug 9, 2022, Alexandre Oliva wrote: > Ping? Ping? Refreshed, added setting of ENUM_UNDERLYING_TYPE, retested on x86_64-linux-gnu (also on gcc-13). Introduce hardbool attribute for C This patch introduces hardened booleans in C. The hardbool attribute, when attached to an integral type,

Re: [PATCH] Introduce hardbool attribute for C

2022-08-09 Thread Alexandre Oliva via Gcc-patches
Ping? (sorry, Joseph, I failed to Cc: you last time) https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598034.html https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598084.html On Jul 7, 2022, Alexandre Oliva wrote: > for gcc/c-family/ChangeLog > * c-attribs.cc (c_common_attribute_

Re: [PATCH] Introduce hardbool attribute for C

2022-07-11 Thread Richard Biener via Gcc-patches
On Fri, Jul 8, 2022 at 5:29 PM Alexandre Oliva wrote: > > On Jul 8, 2022, Richard Biener wrote: > > > Does this follow some other compilers / language? > > It is analogous to Ada's booleans with representation clauses and > runtime validation checking at use points. > > > Is such feature used in

Re: [PATCH] Introduce hardbool attribute for C

2022-07-08 Thread Alexandre Oliva via Gcc-patches
On Jul 8, 2022, Richard Biener wrote: > Does this follow some other compilers / language? It is analogous to Ada's booleans with representation clauses and runtime validation checking at use points. > Is such feature used in existing code? Not that I know. The attribute name was my choice.

Re: [PATCH] Introduce hardbool attribute for C

2022-07-08 Thread Alexandre Oliva via Gcc-patches
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 a63a9415

Re: [PATCH] Introduce hardbool attribute for C

2022-07-08 Thread Sebastian Huber
On 08.07.22 08:58, Richard Biener via Gcc-patches wrote: On Thu, Jul 7, 2022 at 10:00 PM Alexandre Oliva via Gcc-patches wrote: This patch introduces hardened booleans in C. The hardbool attribute, when attached to an integral type, turns it into an enumerate type with boolean semantics, usi

Re: [PATCH] Introduce hardbool attribute for C

2022-07-07 Thread Richard Biener via Gcc-patches
On Thu, Jul 7, 2022 at 10:00 PM Alexandre Oliva via Gcc-patches wrote: > > > This patch introduces hardened booleans in C. The hardbool attribute, > when attached to an integral type, turns it into an enumerate type > with boolean semantics, using the named or implied constants as > representatio

[PATCH] Introduce hardbool attribute for C

2022-07-07 Thread Alexandre Oliva via Gcc-patches
This patch introduces hardened booleans in C. The hardbool attribute, when attached to an integral type, turns it into an enumerate type with boolean semantics, using the named or implied constants as representations for false and true. Expressions of such types decay to _Bool, trapping if the