aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-gcc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/rust-gcc.cc')
-rw-r--r--gcc/rust/rust-gcc.cc36
1 files changed, 28 insertions, 8 deletions
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 273ab78..72aef08 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -592,23 +592,24 @@ function_ptr_type (tree result_type, const std::vector<tree> &parameters,
// Make a struct type.
tree
-struct_type (const std::vector<typed_identifier> &fields)
+struct_type (const std::vector<typed_identifier> &fields, bool layout)
{
- return fill_in_fields (make_node (RECORD_TYPE), fields);
+ return fill_in_fields (make_node (RECORD_TYPE), fields, layout);
}
// Make a union type.
tree
-union_type (const std::vector<typed_identifier> &fields)
+union_type (const std::vector<typed_identifier> &fields, bool layout)
{
- return fill_in_fields (make_node (UNION_TYPE), fields);
+ return fill_in_fields (make_node (UNION_TYPE), fields, layout);
}
// Fill in the fields of a struct or union type.
tree
-fill_in_fields (tree fill, const std::vector<typed_identifier> &fields)
+fill_in_fields (tree fill, const std::vector<typed_identifier> &fields,
+ bool layout)
{
tree field_trees = NULL_TREE;
tree *pp = &field_trees;
@@ -625,7 +626,9 @@ fill_in_fields (tree fill, const std::vector<typed_identifier> &fields)
pp = &DECL_CHAIN (field);
}
TYPE_FIELDS (fill) = field_trees;
- layout_type (fill);
+
+ if (layout)
+ layout_type (fill);
// Because Rust permits converting between named struct types and
// equivalent struct types, for which we use VIEW_CONVERT_EXPR, and
@@ -939,7 +942,7 @@ operator_to_tree_code (NegationOperator op)
case NegationOperator::NEGATE:
return NEGATE_EXPR;
case NegationOperator::NOT:
- return TRUTH_NOT_EXPR;
+ return BIT_NOT_EXPR;
default:
rust_unreachable ();
}
@@ -1071,6 +1074,12 @@ arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op, tree left,
if (left == error_mark_node || right == error_mark_node)
return error_mark_node;
+ // unwrap the const decls if set
+ if (TREE_CODE (left) == CONST_DECL)
+ left = DECL_INITIAL (left);
+ if (TREE_CODE (right) == CONST_DECL)
+ right = DECL_INITIAL (right);
+
/* We need to determine if we're doing floating point arithmetics of integer
arithmetics. */
bool floating_point = is_floating_point (left);
@@ -1103,6 +1112,17 @@ arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op, tree left,
if (floating_point && extended_type != NULL_TREE)
ret = convert (original_type, ret);
+ if (op == ArithmeticOrLogicalOperator::DIVIDE
+ && (integer_zerop (right) || fixed_zerop (right)))
+ {
+ rust_error_at (location, "division by zero");
+ }
+ else if (op == ArithmeticOrLogicalOperator::LEFT_SHIFT
+ && (compare_tree_int (right, TYPE_PRECISION (TREE_TYPE (ret))) >= 0))
+ {
+ rust_error_at (location, "left shift count >= width of type");
+ }
+
return ret;
}
@@ -1338,7 +1358,7 @@ constructor_expression (tree type_tree, bool is_variant,
if (!TREE_CONSTANT (elt->value))
is_constant = false;
}
- gcc_assert (field == NULL_TREE);
+ // gcc_assert (field == NULL_TREE);
}
}