Make string and char pointers comparable
This commit is contained in:
@ -1,3 +1,20 @@
|
||||
/* elna-generic.cc -- Visitor generating a GENERIC tree.
|
||||
Copyright (C) 2025 Free Software Foundation, Inc.
|
||||
|
||||
GCC is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
GCC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GCC; see the file COPYING3. If not see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "elna/gcc/elna-generic.h"
|
||||
@ -295,6 +312,7 @@ namespace gcc
|
||||
tree index_constant = build_int_cstu(index_type, string->number().size());
|
||||
tree element_type = this->symbol_map->lookup("Char");
|
||||
tree string_type = build_array_type(element_type, build_index_type(index_constant));
|
||||
tree string_record = this->symbol_map->lookup("String");
|
||||
|
||||
tree string_literal = build_string(string->number().size(), string->number().c_str());
|
||||
TREE_TYPE(string_literal) = string_type;
|
||||
@ -302,12 +320,11 @@ namespace gcc
|
||||
TREE_READONLY(string_literal) = 1;
|
||||
TREE_STATIC(string_literal) = 1;
|
||||
|
||||
string_type = build_pointer_type(element_type);
|
||||
string_type = TREE_TYPE(TREE_CHAIN(TYPE_FIELDS(string_record)));
|
||||
string_literal = build4(ARRAY_REF, element_type, string_literal, integer_zero_node, NULL_TREE, NULL_TREE);
|
||||
string_literal = build1(ADDR_EXPR, string_type, string_literal);
|
||||
|
||||
vec<constructor_elt, va_gc> *elms = NULL;
|
||||
tree string_record = this->symbol_map->lookup("String");
|
||||
CONSTRUCTOR_APPEND_ELT(elms, TYPE_FIELDS(string_record), index_constant);
|
||||
CONSTRUCTOR_APPEND_ELT(elms, TREE_CHAIN(TYPE_FIELDS(string_record)), string_literal);
|
||||
|
||||
@ -373,11 +390,11 @@ namespace gcc
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (left_type != right_type && !are_compatible_pointers(left, right))
|
||||
if (left_type != right_type && !are_compatible_pointers(left, right) && !are_compatible_pointers(right, left))
|
||||
{
|
||||
error_at(expression_location,
|
||||
"invalid operands of type %s and %s for operator %s",
|
||||
print_type(left_type), print_type(right_type),
|
||||
print_type(left_type).c_str(), print_type(right_type).c_str(),
|
||||
boot::print_binary_operator(expression->operation()));
|
||||
this->current_expression = error_mark_node;
|
||||
return;
|
||||
@ -719,7 +736,7 @@ namespace gcc
|
||||
return;
|
||||
}
|
||||
if (TREE_TYPE(this->current_expression) == TREE_TYPE(lvalue)
|
||||
|| (is_pointer_type(TREE_TYPE(lvalue)) && this->current_expression == null_pointer_node))
|
||||
|| are_compatible_pointers(lvalue, this->current_expression))
|
||||
{
|
||||
tree assignment = build2_loc(statement_location, MODIFY_EXPR,
|
||||
void_type_node, lvalue, this->current_expression);
|
||||
@ -731,8 +748,8 @@ namespace gcc
|
||||
{
|
||||
error_at(statement_location,
|
||||
"cannot assign value of type %s to variable of type %s",
|
||||
print_type(TREE_TYPE(this->current_expression)),
|
||||
print_type(TREE_TYPE(lvalue)));
|
||||
print_type(TREE_TYPE(this->current_expression)).c_str(),
|
||||
print_type(TREE_TYPE(lvalue)).c_str());
|
||||
this->current_expression = error_mark_node;
|
||||
}
|
||||
}
|
||||
@ -771,7 +788,7 @@ namespace gcc
|
||||
{
|
||||
error_at(get_location(&branch.prerequisite().position()),
|
||||
"expected expression of boolean type but its type is %s",
|
||||
print_type(TREE_TYPE(this->current_expression)));
|
||||
print_type(TREE_TYPE(this->current_expression)).c_str());
|
||||
this->current_expression = error_mark_node;
|
||||
return;
|
||||
}
|
||||
@ -818,7 +835,7 @@ namespace gcc
|
||||
{
|
||||
error_at(get_location(&statement->body().prerequisite().position()),
|
||||
"expected expression of boolean type but its type is %s",
|
||||
print_type(TREE_TYPE(this->current_expression)));
|
||||
print_type(TREE_TYPE(this->current_expression)).c_str());
|
||||
this->current_expression = error_mark_node;
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user