From 2e65c14bef940fa2f7dff4f407178af21488b76e Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 10 May 2022 17:51:05 +0100 Subject: Allow cast of integers to pointers This adds the cast rules of integer types and integer inference variables to pointers. The code-generation needed to remove the bad assertion that all integer literals were always going to be of type integer. This also needed a tweak to a bad port from the cp/constexpr.cc code which assumed that all integer_cst of pointer types would be a zero pointer which was used to detect cases of bad method pointers in CPP which we does not apply here. see gcc/cp/constexpr.cc:6564-6488 Fixes #1226 --- gcc/rust/backend/rust-compile-expr.cc | 1 - gcc/rust/backend/rust-constexpr.cc | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'gcc/rust/backend') 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; } -- cgit v1.1