From patchwork Tue Oct 27 18:03:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1388840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=CgqQ3k4i; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CLKMm6Kk3z9sTD for ; Wed, 28 Oct 2020 05:04:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DFAA3857C6C; Tue, 27 Oct 2020 18:04:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DFAA3857C6C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1603821843; bh=ttvLPa9K5lClRYuj4fpHzRUqlYSonMwy/8qE0e+tB2o=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CgqQ3k4i4DDkJck+b1lYjv838yGN5YHuonIcc44wfBEDCktBXjd1zC+3Gx+BpU/f9 8Cw5XdFZYJHaejx+ZEM3/cLNfzGJn0cE/h4IGXq0yFJNewA8uPvD/c9hFo5c/hHAkL 52JhULTIK7tj24OhMnv1ngUr8teD+icfQwD4o8PY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 46B383857C6C for ; Tue, 27 Oct 2020 18:03:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 46B383857C6C Received: by mail-ej1-x634.google.com with SMTP id s15so3527024ejf.8 for ; Tue, 27 Oct 2020 11:03:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ttvLPa9K5lClRYuj4fpHzRUqlYSonMwy/8qE0e+tB2o=; b=U1zJ5pVn0iaHXDboj9it7lW6IeV9o//+rsgtHAyqdkdZm2APnnJKNwha7Qgz033XCm R/dOxzxiEpotbb7Dw8MNT0LoB0wYK+uyemWH1ayI5uf8ag8MzDNxBKMl1mInFW4rb95j LnsVXa78Rap4JvusRFxL4IdU9wzoQlok+YwcbYA5t4hSg6H5jCvLUvFDjRDwGx3AytR5 Yju01fJFYNOSsXxm9dgKZihu+ecOAN+jhIsoBxShXUJlE/M1qVkaTClyVGBIGMo3RJE9 JiSfF+Zo+zs2VtZtIiC8nTT/mgZ0tipPWnUA4Upo2zvSfNREqReS3gukDnzy9mSGIQKH nhsQ== X-Gm-Message-State: AOAM531XjsVkolWl9MA0INtxZsN9ZlPsoj/4i550C+OqTqRWSn1L6BlB CzC+FEyleY7qGWio/Kwp5bKiJo+Cvh1KGv53a3NLVW36UNHQsQ== X-Google-Smtp-Source: ABdhPJxKAxao6q7+rV1ZzZFzaDTZCax7W8AhpCBdclPNSXAEVpAFE3QUQAEIKju6dkes0k9sJ3dpe1nJ0gg3YM+SoBQ= X-Received: by 2002:a17:906:e103:: with SMTP id gj3mr3527068ejb.442.1603821837042; Tue, 27 Oct 2020 11:03:57 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 27 Oct 2020 11:03:45 -0700 Message-ID: Subject: Go patch committed: Export notinheap annotation To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This Go frontend patch adds the notinheap annotation to the export data. This is the Go frontend version of https://golang.org/cl/259297. This is required now because that change is in the 1.15.3 release. This requires changing the go/internal/gccgoimporter package, to skip the new annotation. This change will need to be ported to the gc and x/tools repos. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian b7ac5fdbe7352bd33f6e9f8629d1140f278060cb diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 6caece3f894..7d065954502 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -4c1e7a083bdea02759cd5d2054038fb8a4a55ec8 +957591b8a054b692d92203a2420851689875f9c5 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc index 277aa74e571..90a5f6dbcec 100644 --- a/gcc/go/gofrontend/export.cc +++ b/gcc/go/gofrontend/export.cc @@ -1211,6 +1211,9 @@ Export::write_type_definition(const Type* type, int index) this->write_string(nt->named_object()->name()); this->write_c_string("\" "); + if (!nt->in_heap()) + this->write_c_string("notinheap "); + if (nt->is_alias()) this->write_c_string("= "); } diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc index c6c1178bc24..f671416a423 100644 --- a/gcc/go/gofrontend/import.cc +++ b/gcc/go/gofrontend/import.cc @@ -1049,6 +1049,13 @@ Import::read_named_type(int index) this->require_c_string(" "); } + bool in_heap = true; + if (this->match_c_string("notinheap")) + { + this->require_c_string("notinheap "); + in_heap = false; + } + bool is_alias = false; if (this->match_c_string("= ")) { @@ -1102,7 +1109,14 @@ Import::read_named_type(int index) // declaration of a type defined in some other file. Type* type; if (this->match_c_string(">") || this->match_c_string("\n")) - type = this->types_[index]; + { + type = this->types_[index]; + if (!in_heap) + go_error_at(this->location_, + ("import error at %d for type index %d: " + "forward declaration marked notinheap"), + this->pos(), index); + } else { if (no->is_type_declaration()) @@ -1117,6 +1131,8 @@ Import::read_named_type(int index) // This type has not yet been imported. ntype->clear_is_visible(); + if (!in_heap) + ntype->set_not_in_heap(); if (is_alias) ntype->set_is_alias(); diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index eb9c766b742..f3bcf2eabd4 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -6048,7 +6048,7 @@ Struct_type::do_hash_might_panic() // Return whether this struct type is permitted to be in the heap. bool -Struct_type::do_in_heap() +Struct_type::do_in_heap() const { const Struct_field_list* fields = this->fields_; if (fields == NULL) diff --git a/gcc/go/gofrontend/types.h b/gcc/go/gofrontend/types.h index ccd12686d41..9ac851699d2 100644 --- a/gcc/go/gofrontend/types.h +++ b/gcc/go/gofrontend/types.h @@ -667,7 +667,7 @@ class Type // Whether the type is permitted in the heap. bool - in_heap() + in_heap() const { return this->do_in_heap(); } // Return a hash code for this type for the method hash table. @@ -1120,7 +1120,7 @@ class Type { return false; } virtual bool - do_in_heap() + do_in_heap() const { return true; } virtual unsigned int @@ -2660,7 +2660,7 @@ class Struct_type : public Type do_hash_might_panic(); bool - do_in_heap(); + do_in_heap() const; unsigned int do_hash_for_method(Gogo*, int) const; @@ -2842,7 +2842,7 @@ class Array_type : public Type { return this->length_ != NULL && this->element_type_->hash_might_panic(); } bool - do_in_heap() + do_in_heap() const { return this->length_ == NULL || this->element_type_->in_heap(); } unsigned int @@ -3591,7 +3591,7 @@ class Named_type : public Type do_needs_key_update(); bool - do_in_heap() + do_in_heap() const { return this->in_heap_ && this->type_->in_heap(); } unsigned int @@ -3754,7 +3754,7 @@ class Forward_declaration_type : public Type { return this->real_type()->needs_key_update(); } bool - do_in_heap() + do_in_heap() const { return this->real_type()->in_heap(); } unsigned int diff --git a/libgo/go/go/internal/gccgoimporter/parser.go b/libgo/go/go/internal/gccgoimporter/parser.go index e2ef33f7ae6..1b1d07d3f6e 100644 --- a/libgo/go/go/internal/gccgoimporter/parser.go +++ b/libgo/go/go/internal/gccgoimporter/parser.go @@ -517,6 +517,13 @@ func (p *parser) parseNamedType(nlist []interface{}) types.Type { p.errorf("%v has nil type", obj) } + if p.tok == scanner.Ident && p.lit == "notinheap" { + p.next() + // The go/types package has no way of recording that + // this type is marked notinheap. Presumably no user + // of this package actually cares. + } + // type alias if p.tok == '=' { p.next()