From: Mark Wielaard <mark@klomp.org>
To: gcc-rust@gcc.gnu.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] Use builtin bool instead of creating new bool types for ComparisonExpr
Date: Sat, 14 Aug 2021 23:50:06 +0200 [thread overview]
Message-ID: <20210814215006.90608-1-mark@klomp.org> (raw)
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
reply other threads:[~2021-08-14 21:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210814215006.90608-1-mark@klomp.org \
--to=mark@klomp.org \
--cc=gcc-rust@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).