summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-08-14 23:38:11 +0200
committerMark Wielaard <mark@klomp.org>2021-08-16 23:30:49 +0200
commit5b229ddbf41c9e74fcce930c26101c1d34a5c9d1 (patch)
tree43d75121ca9c9b69b3baf9ca04271d39b73e3b0b
parentMerge #630 (diff)
downloadgccrs-bools_eq.tar.gz
gccrs-bools_eq.tar.bz2
gccrs-bools_eq.tar.xz
Use builtin bool instead of creating new bool types for ComparisonExprbools_eq
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.
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h6
-rw-r--r--gcc/testsuite/rust/compile/torture/bools_eq.rs18
2 files changed, 20 insertions, 4 deletions
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:
630 if (result == nullptr || result->get_kind () == TyTy::TypeKind::ERROR) 630 if (result == nullptr || result->get_kind () == TyTy::TypeKind::ERROR)
631 return; 631 return;
632 632
633 // we expect this to be 633 bool ok = context->lookup_builtin ("bool", &infered);
634 infered = new TyTy::BoolType (expr.get_mappings ().get_hirid ()); 634 rust_assert (ok);
635 infered->append_reference (lhs->get_ref ());
636 infered->append_reference (rhs->get_ref ());
637 } 635 }
638 636
639 void visit (HIR::LazyBooleanExpr &expr) override 637 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 @@
1extern "C"
2{
3 fn abort ();
4}
5
6fn beq (a: bool, b: bool) -> bool
7{
8 let bools_eq = a == b;
9 bools_eq
10}
11
12pub fn main ()
13{
14 let a = true;
15 let b = false;
16 let r = beq (a, b);
17 if r { unsafe { abort (); } }
18}