* [PATCH] Use builtin bool instead of creating new bool types for ComparisonExpr
@ 2021-08-14 21:50 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2021-08-14 21:50 UTC (permalink / raw)
To: gcc-rust; +Cc: Mark Wielaard
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-14 21:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14 21:50 [PATCH] Use builtin bool instead of creating new bool types for ComparisonExpr Mark Wielaard
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).