[gccgo] Reinit varasm if unsafe is imported

Message ID mcrhbifo4i8.fsf@google.com
State New
Headers show

Commit Message

Ian Taylor Aug. 28, 2010, 2:27 a.m.
Normally for Go we can set flag_strict_aliasing.  However, if the unsafe
package is imported, Go permits pointers to be cast from one type to
another, so we must act as though -fno-strict-aliasing is set.  This can
only be determined after the compilation.

This mostly works fine, but unfortunately init_varasm_once is called
before the compilation, and it calls get_alias_set.  Since at that point
flag_strict_aliasing will normally be set, get_alias_set will return a
non-zero value.  If we later reset flag_strict_aliasing because unsafe
is imported, we will then trip an assert in
mems_in_disjoint_alias_sets_p in alias.c, which says that if
flag_strict_aliasing is false all alias sets should be zero.

This patch gets around this collision of expectations by re-initing
varasm when flag_strict_aliasing is clear.  This is hardly ideal, but it
will do for now.  Committed to gccgo branch.



diff -r d9380a2f70bf go/gogo-tree.cc
--- a/go/gogo-tree.cc	Fri Aug 27 08:40:14 2010 -0700
+++ b/go/gogo-tree.cc	Fri Aug 27 19:23:02 2010 -0700
@@ -22,6 +22,7 @@ 
 #include "output.h"
 #include "tm_p.h"
 #include "diagnostic.h"
+#include "rtl.h"
 #include "go-c.h"
@@ -810,6 +811,11 @@ 
       // Importing the "unsafe" package automatically disables TBAA.
       flag_strict_aliasing = false;
+      // This is a real hack.  init_varasm_once has already grabbed an
+      // alias set, which we don't want when we aren't going strict
+      // aliasing.  We reinitialize to make it do it again.  FIXME.
+      init_varasm_once();
   wrapup_global_declarations(vec, count);
diff -r 2bba0080d755 go/Make-lang.in
--- a/go/Make-lang.in	Fri Aug 27 19:23:42 2010 -0700
+++ b/go/Make-lang.in	Fri Aug 27 19:26:48 2010 -0700
@@ -158,7 +158,7 @@ 
 	$(GO_C_H) gt-go-go-lang.h gtype-go.h
 go/gogo-tree.o: go/gogo-tree.cc $(GO_SYSTEM_H) $(TREE_H) $(GIMPLE_H) \
 	tree-iterator.h $(CGRAPH_H) langhooks.h convert.h output.h \
 go/gogo.o: go/gogo.cc $(GO_SYSTEM_H) go/go-dump.h $(GO_LEX_H) $(GO_TYPES_H) \