From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gandi.kataplop.net (gandi.kataplop.net [46.226.111.114]) by sourceware.org (Postfix) with ESMTPS id D520C3898C79 for ; Mon, 16 Aug 2021 07:48:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D520C3898C79 Received: from [::1] (helo=rl.kataplop.net) by gandi.kataplop.net with esmtp (Exim 4.92) (envelope-from ) id 1mFXMA-0000f9-Vz; Mon, 16 Aug 2021 09:48:32 +0200 MIME-Version: 1.0 Date: Mon, 16 Aug 2021 07:48:26 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: RainLoop/1.14.0 From: dkm@kataplop.net Message-ID: <0e8cd730cb7867bd1970b20d99a55f1c@kataplop.net> Subject: Re: [PATCH] Add support for const bool and const float To: "Mark Wielaard" , gcc-rust@gcc.gnu.org In-Reply-To: <20210815195526.59273-1-mark@klomp.org> References: <20210815195526.59273-1-mark@klomp.org> X-Spam_score: -1.0 X-Spam_bar: - X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Aug 2021 07:48:44 -0000 Hey!=0A=0ALooks like tests are not OK, at least in the github action. Can= 't test but maybe you can confirm this issue ?=0A=0A# of unexpected failu= res 14=0A=0AMarc=0A=0AAugust 15, 2021 9:55 PM, "Mark Wielaard" wrote:=0A=0A> Handle BOOL and FLOAT in ConstFoldExpr::visit (HIR::= LiteralExpr) to=0A> make it possible to create const bool, f32 and f64 co= nstants. Add a=0A> new testcase "primconsts.rs". Not yet handled are cons= t char and &str=0A> types.=0A> ---=0A> gcc/rust/typecheck/rust-hir-const-= fold.h | 30 ++++++++=0A> .../rust/compile/torture/primconsts.rs | 72 ++++= +++++++++++++++=0A> 2 files changed, 102 insertions(+)=0A> create mode 10= 0644 gcc/testsuite/rust/compile/torture/primconsts.rs=0A> =0A> diff --git= a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir= -const-fold.h=0A> index f6c66163fc1..8efbb183403 100644=0A> --- a/gcc/rus= t/typecheck/rust-hir-const-fold.h=0A> +++ b/gcc/rust/typecheck/rust-hir-c= onst-fold.h=0A> @@ -315,6 +315,36 @@ public:=0A> }=0A> return;=0A> =0A> += case HIR::Literal::BOOL: {=0A> + bool bval =3D literal_value->as_string = ().compare ("true") =3D=3D 0;=0A> + folded =3D ctx->get_backend ()->boole= an_constant_expression (bval);=0A> + }=0A> + return;=0A> +=0A> + case HIR= ::Literal::FLOAT: {=0A> + mpfr_t fval;=0A> + if (mpfr_init_set_str (fval,= literal_value->as_string ().c_str (), 10,=0A> + MPFR_RNDN)=0A> + !=3D 0)= =0A> + {=0A> + rust_fatal_error (expr.get_locus (),=0A> + "bad floating-p= oint number in literal");=0A> + return;=0A> + }=0A> +=0A> + TyTy::BaseTyp= e *tyty =3D nullptr;=0A> + if (!tyctx->lookup_type (expr.get_mappings ().= get_hirid (), &tyty))=0A> + {=0A> + rust_fatal_error (expr.get_locus (),= =0A> + "did not resolve type for this literal expr");=0A> + return;=0A> += }=0A> +=0A> + Btype *type =3D ConstFoldType::fold (tyty, ctx->get_backen= d ());=0A> + folded =3D ctx->get_backend ()->float_constant_expression (t= ype, fval);=0A> + }=0A> + return;=0A> +=0A> /* handle other literals */= =0A> =0A> default:=0A> diff --git a/gcc/testsuite/rust/compile/torture/pr= imconsts.rs=0A> b/gcc/testsuite/rust/compile/torture/primconsts.rs=0A> ne= w file mode 100644=0A> index 00000000000..bcf9456d059=0A> --- /dev/null= =0A> +++ b/gcc/testsuite/rust/compile/torture/primconsts.rs=0A> @@ -0,0 += 1,72 @@=0A> +const TRUE: bool =3D true;=0A> +const FALSE: bool =3D !TRUE;= =0A> +=0A> +const U8ZERO: u8 =3D 0;=0A> +const U8ONE: u8 =3D U8ZERO + 1;= =0A> +const U16ZERO: u16 =3D 0;=0A> +const U16ONE: u16 =3D U16ZERO + 1;= =0A> +const U32ZERO: u32 =3D 0;=0A> +const U32ONE: u32 =3D U32ZERO + 1;= =0A> +const U64ZERO: u64 =3D 0;=0A> +const U64ONE: u64 =3D U64ZERO + 1;= =0A> +const U128ZERO: u128 =3D 0;=0A> +const U128ONE: u128 =3D U128ZERO += 1;=0A> +=0A> +const I8ZERO: i8 =3D 0;=0A> +const I8ONE: i8 =3D I8ZERO + = 1;=0A> +const I16ZERO: i16 =3D 0;=0A> +const I16ONE: i16 =3D I16ZERO + 1;= =0A> +const I32ZERO: i32 =3D 0;=0A> +const I32ONE: i32 =3D I32ZERO + 1;= =0A> +const I64ZERO: i64 =3D 0;=0A> +const I64ONE: i64 =3D I64ZERO + 1;= =0A> +const I128ZERO: i128 =3D 0;=0A> +const I128ONE: i128 =3D I128ZERO += 1;=0A> +=0A> +const F32ZERO: f32 =3D 0.0;=0A> +const F32ONE: f32 =3D F32= ZERO + 1.0;=0A> +const F64ZERO: f64 =3D 0.0;=0A> +const F64ONE: f64 =3D F= 64ZERO + 1.0;=0A> +=0A> +const USIZEZERO: usize =3D 0;=0A> +const USIZEON= E: usize =3D USIZEZERO + 1;=0A> +const ISIZEZERO: isize =3D 0;=0A> +const= ISIZEONE: isize =3D ISIZEZERO + 1;=0A> +=0A> +/* Not yet supported =0A> = +const CHARPI: char =3D '\u{03C0}';=0A> +const STRHELLO: &str =3D "Hello = World!";=0A> +*/=0A> +=0A> +extern "C" { fn abort (); }=0A> +=0A> +pub fn= main ()=0A> +{=0A> + if TRUE =3D=3D FALSE { unsafe { abort (); } }=0A> += if U8ZERO > U8ONE { unsafe { abort (); } }=0A> + if U16ZERO > U16ONE { u= nsafe { abort (); } }=0A> + if U32ZERO > U32ONE { unsafe { abort (); } }= =0A> + if U64ZERO > U64ONE { unsafe { abort (); } }=0A> + if U128ZERO > U= 128ONE { unsafe { abort (); } }=0A> +=0A> + if I8ONE <=3D I8ZERO { unsafe= { abort (); } }=0A> + if I16ONE <=3D I16ZERO { unsafe { abort (); } }=0A= > + if I32ONE <=3D I32ZERO { unsafe { abort (); } }=0A> + if I64ONE <=3D = I64ZERO { unsafe { abort (); } }=0A> + if I128ONE <=3D I128ZERO { unsafe = { abort (); } }=0A> +=0A> + if F32ZERO + F32ONE !=3D F32ONE { unsafe { ab= ort (); } }=0A> + if F64ZERO + F64ONE !=3D F64ONE { unsafe { abort (); } = }=0A> +=0A> + if USIZEZERO + USIZEONE - USIZEONE + USIZEZERO !=3D USIZEZE= RO=0A> + {=0A> + unsafe { abort (); }=0A> + }=0A> + if ISIZEZERO + ISIZEO= NE - ISIZEONE + ISIZEZERO !=3D ISIZEZERO=0A> + {=0A> + unsafe { abort ();= }=0A> + }=0A> +=0A> + // if CHARPI !=3D '\u{03c0}' { unsafe { abort (); = } }=0A> + // if STRHELLO !=3D "Hello World!" { unsafe { abort (); } }=0A>= +}=0A> -- =0A> 2.32.0=0A> =0A> -- =0A> Gcc-rust mailing list=0A> Gcc-rus= t@gcc.gnu.org=0A> https://gcc.gnu.org/mailman/listinfo/gcc-rust