Check only a pointer can be dereferenced

This commit is contained in:
2025-03-23 10:14:04 +01:00
parent 07ed40cc24
commit 6ccb195c09
3 changed files with 45 additions and 33 deletions

View File

@ -1071,9 +1071,20 @@ namespace elna::gcc
void generic_visitor::visit(boot::dereference_expression *expression)
{
expression->base().accept(this);
location_t expression_location = get_location(&expression->position());
tree expression_type = TREE_TYPE(this->current_expression);
this->current_expression = build1_loc(get_location(&expression->position()), INDIRECT_REF,
TREE_TYPE(TREE_TYPE(this->current_expression)), this->current_expression);
if (is_pointer_type(expression_type))
{
this->current_expression = build1_loc(expression_location, INDIRECT_REF,
TREE_TYPE(expression_type), this->current_expression);
}
else
{
error_at(expression_location, "Type '%s' cannot be dereferenced, it is not a pointer",
print_type(expression_type).c_str());
this->current_expression = error_mark_node;
}
}
void generic_visitor::visit(boot::assign_statement *statement)