From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id A0B2D3861004 for ; Mon, 16 Aug 2021 21:44:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0B2D3861004 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (unknown [172.31.128.41]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 46A7F302FBB1; Mon, 16 Aug 2021 23:44:40 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id D6F222E83136; Mon, 16 Aug 2021 23:44:39 +0200 (CEST) Date: Mon, 16 Aug 2021 23:44:39 +0200 From: Mark Wielaard To: dkm@kataplop.net, gcc-rust@gcc.gnu.org Subject: Re: [PATCH] Add support for const bool and const float Message-ID: References: <20210815195526.59273-1-mark@klomp.org> <0e8cd730cb7867bd1970b20d99a55f1c@kataplop.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Ej8+iDzFxng3IGNE" Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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 21:44:58 -0000 --Ej8+iDzFxng3IGNE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Mon, Aug 16, 2021 at 11:03:19PM +0200, Mark Wielaard wrote: > Now having replicated it locally the rust.log shows: > > /srv/gccrs/gccrs/gcc/testsuite/rust/compile/torture/ifunaryexpr.rs: In function 'main': > /srv/gccrs/gccrs/gcc/testsuite/rust/compile/torture/ifunaryexpr.rs:8:5: error: mismatching comparison operand types > const i32 > bool > if (n != 0) goto ; else goto ; > /srv/gccrs/gccrs/gcc/testsuite/rust/compile/torture/ifunaryexpr.rs:8:5: internal compiler error: 'verify > _gimple' failed > 0xf38fbd verify_gimple_in_seq(gimple*) > ../../gccrs/gcc/tree-cfg.c:5157 > 0xc72346 gimplify_body(tree_node*, bool) > ../../gccrs/gcc/gimplify.c:15401 > 0xc724cd gimplify_function_tree(tree_node*) > ../../gccrs/gcc/gimplify.c:15472 > 0xab0dc7 cgraph_node::analyze() > ../../gccrs/gcc/cgraphunit.c:670 > 0xab38b7 analyze_functions > ../../gccrs/gcc/cgraphunit.c:1236 > 0xab454d symbol_table::finalize_compilation_unit() > ../../gccrs/gcc/cgraphunit.c:2514 > > So, my patch created bad gimple. I'll try to track it down. I figured it out. There was another bug in the ComparisonExpr type checker the result is a bool type but the argument types only need to have compatible types, they don't have to be bools. Fixed patch attached. Also on https://code.wildebeest.org/git/user/mjw/gccrs/commit/?h=bools_eq Cheers, Mark --Ej8+iDzFxng3IGNE Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Use-builtin-bool-instead-of-creating-new-bool-types-.patch" >From 5b229ddbf41c9e74fcce930c26101c1d34a5c9d1 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 14 Aug 2021 23:38:11 +0200 Subject: [PATCH] Use builtin bool instead of creating new bool types for ComparisonExpr The TypeCheckExpr creates a new TyTy::BoolType for a ComparisonExpr. This new BoolType is unknown to TyTyResolveCompile which causes a crash when trying to compile the inferred new BoolType. Resolve this by looking up the builtin bool type. The new "bools_eq.rs" testcase uses several bools which show this issue. Also the lhs and rhs types need to be compatible, but don't need to be bool type themselves. So don't append the reference to the inferred type. The existing "ifunaryexpr.rs" testcase will fail without this fix. --- gcc/rust/typecheck/rust-hir-type-check-expr.h | 6 ++---- gcc/testsuite/rust/compile/torture/bools_eq.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/torture/bools_eq.rs diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index d88cb0b7f1d..a833822e9b3 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -630,10 +630,8 @@ public: if (result == nullptr || result->get_kind () == TyTy::TypeKind::ERROR) return; - // we expect this to be - infered = new TyTy::BoolType (expr.get_mappings ().get_hirid ()); - infered->append_reference (lhs->get_ref ()); - infered->append_reference (rhs->get_ref ()); + bool ok = context->lookup_builtin ("bool", &infered); + rust_assert (ok); } void visit (HIR::LazyBooleanExpr &expr) override diff --git a/gcc/testsuite/rust/compile/torture/bools_eq.rs b/gcc/testsuite/rust/compile/torture/bools_eq.rs new file mode 100644 index 00000000000..965127b5d54 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/bools_eq.rs @@ -0,0 +1,18 @@ +extern "C" +{ + fn abort (); +} + +fn beq (a: bool, b: bool) -> bool +{ + let bools_eq = a == b; + bools_eq +} + +pub fn main () +{ + let a = true; + let b = false; + let r = beq (a, b); + if r { unsafe { abort (); } } +} -- 2.32.0 --Ej8+iDzFxng3IGNE--