aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc1
-rw-r--r--gcc/rust/backend/rust-constexpr.cc12
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.h12
-rw-r--r--gcc/rust/typecheck/rust-tyty-cast.h11
-rw-r--r--gcc/testsuite/rust/compile/issue-1226.rs6
-rw-r--r--gcc/testsuite/rust/compile/issue-1234.rs4
6 files changed, 31 insertions, 15 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 1cf4e3d..0307df1 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -903,7 +903,6 @@ CompileExpr::compile_integer_literal (const HIR::LiteralExpr &expr,
const auto literal_value = expr.get_literal ();
tree type = TyTyResolveCompile::compile (ctx, tyty);
- rust_assert (TREE_CODE (type) == INTEGER_TYPE);
mpz_t ival;
if (mpz_init_set_str (ival, literal_value.as_string ().c_str (), 10) != 0)
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc
index 1b0515e..aee41e4 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -59,17 +59,7 @@ ConstCtx::constexpr_expression (tree t)
{
if (TREE_OVERFLOW (t))
{
- rust_error_at (Location (loc), "overflow in constant expression");
- return t;
- }
-
- if (TREE_CODE (t) == INTEGER_CST && TYPE_PTR_P (TREE_TYPE (t))
- && !integer_zerop (t))
- {
- // FIXME check does this actually work to print out tree types
- rust_error_at (Location (loc),
- "value %qE of type %qT is not a constant expression",
- t, TREE_TYPE (t));
+ error_at (loc, "overflow in constant expression");
return t;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index f1dff2c..b20a048 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -555,7 +555,17 @@ public:
return;
}
- infered = lhs->unify (rhs);
+ switch (expr.get_expr_type ())
+ {
+ case ArithmeticOrLogicalOperator::LEFT_SHIFT:
+ case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
+ infered = rhs->cast (lhs);
+ break;
+
+ default:
+ infered = lhs->unify (rhs);
+ break;
+ }
}
void visit (HIR::ComparisonExpr &expr) override
diff --git a/gcc/rust/typecheck/rust-tyty-cast.h b/gcc/rust/typecheck/rust-tyty-cast.h
index 0e0e7b0..5ca68d0 100644
--- a/gcc/rust/typecheck/rust-tyty-cast.h
+++ b/gcc/rust/typecheck/rust-tyty-cast.h
@@ -588,8 +588,11 @@ public:
void visit (PointerType &type) override
{
- bool is_valid
- = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
+ bool is_general_infer_var
+ = base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL;
+ bool is_integral_infer_var
+ = base->get_infer_kind () == TyTy::InferType::InferTypeKind::INTEGRAL;
+ bool is_valid = is_general_infer_var || is_integral_infer_var;
if (is_valid)
{
resolved = type.clone ();
@@ -939,6 +942,8 @@ public:
void visit (ISizeType &type) override { resolved = type.clone (); }
+ void visit (PointerType &type) override { resolved = type.clone (); }
+
private:
BaseType *get_base () override { return base; }
@@ -975,6 +980,8 @@ public:
void visit (ISizeType &type) override { resolved = type.clone (); }
+ void visit (PointerType &type) override { resolved = type.clone (); }
+
void visit (CharType &type) override
{
// error[E0604]: only `u8` can be cast as `char`, not `i32`
diff --git a/gcc/testsuite/rust/compile/issue-1226.rs b/gcc/testsuite/rust/compile/issue-1226.rs
new file mode 100644
index 0000000..f5f9e5f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1226.rs
@@ -0,0 +1,6 @@
+// { dg-additional-options "-w" }
+const TEST: *mut u8 = 123 as *mut u8;
+
+fn test() {
+ let a = TEST;
+}
diff --git a/gcc/testsuite/rust/compile/issue-1234.rs b/gcc/testsuite/rust/compile/issue-1234.rs
new file mode 100644
index 0000000..c6d5932
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1234.rs
@@ -0,0 +1,4 @@
+fn foo() -> u8 {
+ // { dg-warning "function is never used" "" { target *-*-* } .-1 }
+ 1u8 << 2u32
+}