From patchwork Sat Aug 28 02:27:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 62886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 25D09B711A for ; Sat, 28 Aug 2010 12:28:20 +1000 (EST) Received: (qmail 28949 invoked by alias); 28 Aug 2010 02:28:16 -0000 Received: (qmail 28939 invoked by uid 22791); 28 Aug 2010 02:28:15 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 28 Aug 2010 02:28:09 +0000 Received: from hpaq1.eem.corp.google.com (hpaq1.eem.corp.google.com [172.25.149.1]) by smtp-out.google.com with ESMTP id o7S2S6JR005756 for ; Fri, 27 Aug 2010 19:28:07 -0700 Received: from pxi3 (pxi3.prod.google.com [10.243.27.3]) by hpaq1.eem.corp.google.com with ESMTP id o7S2S4iJ007682 for ; Fri, 27 Aug 2010 19:28:05 -0700 Received: by pxi3 with SMTP id 3so1550742pxi.7 for ; Fri, 27 Aug 2010 19:28:04 -0700 (PDT) Received: by 10.142.47.10 with SMTP id u10mr1915071wfu.177.1282962484377; Fri, 27 Aug 2010 19:28:04 -0700 (PDT) Received: from coign.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) by mx.google.com with ESMTPS id 23sm5259281wfa.10.2010.08.27.19.28.02 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 27 Aug 2010 19:28:03 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Reinit varasm if unsafe is imported Date: Fri, 27 Aug 2010 19:27:59 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. Ian 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 \ - $(TM_P_H) $(DIAGNOSTIC_H) $(GO_TYPES_H) $(GO_EXPRESSIONS_H) \ + $(TM_P_H) $(DIAGNOSTIC_H) $(RTL_H) $(GO_TYPES_H) $(GO_EXPRESSIONS_H) \ $(GO_STATEMENTS_H) $(GO_GOGO_H) go/gogo.o: go/gogo.cc $(GO_SYSTEM_H) go/go-dump.h $(GO_LEX_H) $(GO_TYPES_H) \ $(GO_STATEMENTS_H) $(GO_EXPRESSIONS_H) go/dataflow.h $(GO_IMPORT_H) \