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 1A5123858412 for ; Sat, 14 Aug 2021 21:50:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1A5123858412 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 (83-161-181-105.mobile.xs4all.nl [83.161.181.105]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 7D14D302FB9F; Sat, 14 Aug 2021 23:50:25 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id A0AAC2E83133; Sat, 14 Aug 2021 23:50:09 +0200 (CEST) From: Mark Wielaard To: gcc-rust@gcc.gnu.org Cc: Mark Wielaard Subject: [PATCH] Use builtin bool instead of creating new bool types for ComparisonExpr Date: Sat, 14 Aug 2021 23:50:06 +0200 Message-Id: <20210814215006.90608-1-mark@klomp.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 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: Sat, 14 Aug 2021 21:50:37 -0000 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. The new "bools_eq.rs" testcase uses several bools which show this issue. Resolve this by looking up the builtin bool type. --- gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 +- gcc/testsuite/rust/compile/torture/bools_eq.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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..9cf64685e00 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -631,7 +631,7 @@ public: return; // we expect this to be - infered = new TyTy::BoolType (expr.get_mappings ().get_hirid ()); + context->lookup_builtin ("bool", &infered); infered->append_reference (lhs->get_ref ()); infered->append_reference (rhs->get_ref ()); } 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