aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/go-gcc.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2012-03-09 08:25:05 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-03-09 08:25:05 +0000
commit68c5d97bad2d405e2b27826bcb95f224baec6465 (patch)
treebd0a2765d69acdf83a414c1a6f425dc3adc2543d /gcc/go/go-gcc.cc
parent762c279900efedc1407c3c38d98601ddbff575ae (diff)
downloadgcc-68c5d97bad2d405e2b27826bcb95f224baec6465.zip
gcc-68c5d97bad2d405e2b27826bcb95f224baec6465.tar.gz
gcc-68c5d97bad2d405e2b27826bcb95f224baec6465.tar.bz2
compiler: Be more careful to follow GENERIC type rules.
* go-gcc.cc (Gcc_backend::assignment_statement): Convert the rhs to the lhs type if necessary. From-SVN: r185128
Diffstat (limited to 'gcc/go/go-gcc.cc')
-rw-r--r--gcc/go/go-gcc.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 0cc167d..96c1718 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -918,6 +918,30 @@ Gcc_backend::assignment_statement(Bexpression* lhs, Bexpression* rhs,
return this->compound_statement(this->expression_statement(lhs),
this->expression_statement(rhs));
+ // Sometimes the same unnamed Go type can be created multiple times
+ // and thus have multiple tree representations. Make sure this does
+ // not confuse the middle-end.
+ if (TREE_TYPE(lhs_tree) != TREE_TYPE(rhs_tree))
+ {
+ tree lhs_type_tree = TREE_TYPE(lhs_tree);
+ gcc_assert(TREE_CODE(lhs_type_tree) == TREE_CODE(TREE_TYPE(rhs_tree)));
+ if (POINTER_TYPE_P(lhs_type_tree)
+ || INTEGRAL_TYPE_P(lhs_type_tree)
+ || SCALAR_FLOAT_TYPE_P(lhs_type_tree)
+ || COMPLEX_FLOAT_TYPE_P(lhs_type_tree))
+ rhs_tree = fold_convert_loc(location.gcc_location(), lhs_type_tree,
+ rhs_tree);
+ else if (TREE_CODE(lhs_type_tree) == RECORD_TYPE
+ || TREE_CODE(lhs_type_tree) == ARRAY_TYPE)
+ {
+ gcc_assert(int_size_in_bytes(lhs_type_tree)
+ == int_size_in_bytes(TREE_TYPE(rhs_tree)));
+ rhs_tree = fold_build1_loc(location.gcc_location(),
+ VIEW_CONVERT_EXPR,
+ lhs_type_tree, rhs_tree);
+ }
+ }
+
return this->make_statement(fold_build2_loc(location.gcc_location(),
MODIFY_EXPR,
void_type_node,