On Mon, May 17, 2021 at 6:52 PM Andrew Pinski <pins...@gmail.com> wrote: > > I noticed while debugging why my "A?CST1:CST0" patch was broken for > Ada, I noticed the following ranges for boolean types: > # RANGE [0, 1] NONZERO 1 > _14 = checks__saved_checks_tos.482_2 > 0; > # RANGE [0, 255] NONZERO 1 > _18 = _14 == 0; > _19 = ~_18; > # RANGE [0, 1] NONZERO 1 > _15 = _19; > if (_15 != 0) > goto <bb 7>; [50.00%] > else > goto <bb 6>; [50.00%] > > Seems like there is a misunderstanding of TYPE_UNSIGNED for boolean > types and that is what is causing the problem in the end. As the above > gets optimized to be always true. My patch just happens to cause the > ~_18 to be produced which is later on miscompiled. > > Should TYPE_UNSIGNED be always set for boolean types? > > I am testing the below patch to see if it fixes the problem, if we > should assume TYPE_UNSIGNED is true for boolean types. If we should > not assume that, then there is a problem with conversion between > boolean types that have TYPE_UNSIGNED mismatched.
I went back and noticed this has been discussed before but it does look like the middle-end/gimple is still broken and even worse I have done: (bit_not:boolean_type_node (convert:boolean_type_node @0)) Which means I have done the conversions correctly but they are removed still. So I am still thinking we need to have a discussion about what boolean type node should be and even how boolean types should act during the gimple phase. Thanks, Andrew Pinski > > Thanks, > Andrew Pinski > > diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c > index 232b552a60c..4e839f3b8ab 100644 > --- a/gcc/ada/gcc-interface/decl.c > +++ b/gcc/ada/gcc-interface/decl.c > @@ -1687,7 +1687,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree > gnu_expr, bool definition) > > gnu_type = make_node (is_boolean ? BOOLEAN_TYPE : ENUMERAL_TYPE); > TYPE_PRECISION (gnu_type) = esize; > - TYPE_UNSIGNED (gnu_type) = is_unsigned; > + TYPE_UNSIGNED (gnu_type) = is_boolean ? true : is_unsigned; > set_min_and_max_values_for_integral_type (gnu_type, esize, > TYPE_SIGN (gnu_type)); > process_attributes (&gnu_type, &attr_list, true, gnat_entity);