public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Mark structs to use structural equality
@ 2018-02-03 17:01 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2018-02-03 17:01 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]

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  <iant@golang.org>

* go-gcc.cc (Gcc_backend::fill_in_struct): Mark struct types as
using structural equality.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 648 bytes --]

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;
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-02-03 17:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-03 17:01 Go patch committed: Mark structs to use structural equality Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).