The Go frontend relies on the ability to convert from one struct type
to another, which it does using VIEW_CONVERT_EXPR. For complete type
safety doing this we need to mark struct types as using structural
equality, which we were not doing. We mostly got away with this, but
https://golang.org/issue/23667 shows a case where that fails (many
test failures were caused by a single miscompilation in the library).
This patch changes the Go frontend to GCC interface to mark structs as
using structural equality. Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu and powerpc64le-unknown-linux-gnu. Committed to
mainline.
Ian
2018-02-03 Ian Lance Taylor <[email protected]>
* go-gcc.cc (Gcc_backend::fill_in_struct): Mark struct types as
using structural equality.
Index: gcc/go/go-gcc.cc
===================================================================
--- gcc/go/go-gcc.cc (revision 257319)
+++ gcc/go/go-gcc.cc (working copy)
@@ -962,6 +962,13 @@ Gcc_backend::fill_in_struct(Btype* fill,
}
TYPE_FIELDS(fill_tree) = field_trees;
layout_type(fill_tree);
+
+ // Because Go permits converting between named struct types and
+ // equivalent struct types, for which we use VIEW_CONVERT_EXPR, and
+ // because we don't try to maintain TYPE_CANONICAL for struct types,
+ // we need to tell the middle-end to use structural equality.
+ SET_TYPE_STRUCTURAL_EQUALITY(fill_tree);
+
return fill;
}