From patchwork Fri Apr 15 21:27:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1617941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=YL5Bvrfd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kg8Zb0y69z9sGt for ; Sat, 16 Apr 2022 07:28:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B35C3385780D for ; Fri, 15 Apr 2022 21:28:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B35C3385780D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650058095; bh=ycFWduAovMSd0vqqkIbguaSNJgpwy+kASq1GBjEB8Nk=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YL5Bvrfd/428WTLPodXkPf8J7+4QWU7AADVr2xJA2XA1e1w3g7IxlcDflH3gUDI58 reMaA6R/wOEMpuXVPRFTTFNXwOT3D8zIbeGmPJPE7/U79IbiRiOqDlhfAVrnKGmnRe bLSthakUdieWYNpE35O1/FjHtN4IsPFL0Ta9uY5M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 3CB153858016 for ; Fri, 15 Apr 2022 21:27:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3CB153858016 Received: by mail-ej1-x631.google.com with SMTP id u15so17113177ejf.11 for ; Fri, 15 Apr 2022 14:27:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ycFWduAovMSd0vqqkIbguaSNJgpwy+kASq1GBjEB8Nk=; b=m4fLmotZo5WWH72iQWjg2iJJqdFL/2vwqHJCM3gD6JWjkqJqwQC3H01kWjsZWvfxsb 9RTExM8n05PvjcjI5LZ6/KCbGezSQhIbdVx1gbjXMGHh1mZC5EzOBapoMCT/RRiHJ1er yiWmXbf+lwhKTXfDAyWvUlcf8jP46ZFplarvEexHFs2LOYJEJsVIH8WGCyuH07cdSThW 5SUl0KkXJsrMVZ6SAAxS7eOIhJ14AWNrIWbEofupVQGVTrQJJPmYYoaSdpyMcLKovOJf 2Dmt/ILCU1NCllxHEEEoW8jHxnYNo7lC2dmVkfHlmKFrERKO9vN1PT8osZonVdrLb4zN Oo2w== X-Gm-Message-State: AOAM530EqIzOLs6PqhpP6fTJ6P8UdbA7z1PKJGHrvlgD95Wm8B/uoZ9T DbHsSKItUfPiURYrApbmvSaVx0ueowGvP97nCARZ1dYPzqkDwQ== X-Google-Smtp-Source: ABdhPJxrXDpGPUapX5QXTpSxwWyVfT82tmRoOPQe+K+TTvFMQa4yAU6XyA3jzH0ghLoz+lqNqN1B+Q2LZNYEM5Ad4tE= X-Received: by 2002:a17:907:1611:b0:6ef:5d92:5941 with SMTP id hb17-20020a170907161100b006ef5d925941mr719461ejc.10.1650058051562; Fri, 15 Apr 2022 14:27:31 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 15 Apr 2022 14:27:20 -0700 Message-ID: Subject: Go patch commited: Fix initialization ordering To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" compiler: revert `for package-scope "a = b; b = x" just set "a = x"` This patch to the Go frontend reverts https://go.dev/cl/245098, which introduced incorrect initialization ordering. This patch adjusts the runtime package to work even with that change reverted. Original description of change 245098: This avoids requiring an init function to initialize the variable. This can only be done if x is a static initializer. The go1.15rc1 runtime package relies on this optimization. The package has a variable "var maxSearchAddr = maxOffAddr". The maxSearchAddr variable is used by code that runs before package initialization is complete. This is for https://golang.org/issue/51913. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 5d6db440fd8ec4089fba83760874d70f449037a6 diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 75ee2e3aaca..bcb526c85b9 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -323ab0e6fab89978bdbd83dca9c2ad9c5dcd690f +62fc90f52da2f52cbe3b4f10e560dc6aa59baeb5 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/gogo.cc b/gcc/go/gofrontend/gogo.cc index 30d5c9fcb0b..d35c6baf582 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -1612,31 +1612,16 @@ Gogo::write_globals() // The initializer is constant if it is the zero-value of the // variable's type or if the initial value is an immutable value // that is not copied to the heap. - Expression* init = var->init(); - - // If we see "a = b; b = x", and x is a static - // initializer, just set a to x. - while (init != NULL && init->var_expression() != NULL) - { - Named_object* ino = init->var_expression()->named_object(); - if (!ino->is_variable() || ino->package() != NULL) - break; - Expression* ino_init = ino->var_value()->init(); - if (ino->var_value()->has_pre_init() - || ino_init == NULL - || !ino_init->is_static_initializer()) - break; - init = ino_init; - } - - bool is_static_initializer; - if (init == NULL) + bool is_static_initializer = false; + if (var->init() == NULL) is_static_initializer = true; else { Type* var_type = var->type(); - init = Expression::make_cast(var_type, init, var->location()); - is_static_initializer = init->is_static_initializer(); + Expression* init = var->init(); + Expression* init_cast = + Expression::make_cast(var_type, init, var->location()); + is_static_initializer = init_cast->is_static_initializer(); } // Non-constant variable initializations might need to create @@ -1655,15 +1640,7 @@ Gogo::write_globals() } var_init_fn = init_fndecl; } - - Bexpression* var_binit; - if (init == NULL) - var_binit = NULL; - else - { - Translate_context context(this, var_init_fn, NULL, NULL); - var_binit = init->get_backend(&context); - } + Bexpression* var_binit = var->get_init(this, var_init_fn); if (var_binit == NULL) ; diff --git a/libgo/go/runtime/mpagealloc.go b/libgo/go/runtime/mpagealloc.go index 2725e3b7c7b..5e40da45d17 100644 --- a/libgo/go/runtime/mpagealloc.go +++ b/libgo/go/runtime/mpagealloc.go @@ -87,7 +87,9 @@ const ( // // We alias maxOffAddr just to make it clear that this is the maximum address // for the page allocator's search space. See maxOffAddr for details. -var maxSearchAddr = maxOffAddr +func maxSearchAddr() offAddr { + return maxOffAddr +} // Global chunk index. // @@ -331,13 +333,13 @@ func (p *pageAlloc) init(mheapLock *mutex, sysStat *sysMemStat) { p.sysInit() // Start with the searchAddr in a state indicating there's no free memory. - p.searchAddr = maxSearchAddr + p.searchAddr = maxSearchAddr() // Set the mheapLock. p.mheapLock = mheapLock // Initialize scavenge tracking state. - p.scav.scavLWM = maxSearchAddr + p.scav.scavLWM = maxSearchAddr() } // tryChunkOf returns the bitmap data for the given chunk. @@ -760,7 +762,7 @@ nextLevel: } if l == 0 { // We're at level zero, so that means we've exhausted our search. - return 0, maxSearchAddr + return 0, maxSearchAddr() } // We're not at level zero, and we exhausted the level we were looking in. @@ -854,7 +856,7 @@ func (p *pageAlloc) alloc(npages uintptr) (addr uintptr, scav uintptr) { // exhausted. Otherwise, the heap still might have free // space in it, just not enough contiguous space to // accommodate npages. - p.searchAddr = maxSearchAddr + p.searchAddr = maxSearchAddr() } return 0, 0 } diff --git a/libgo/go/runtime/mpagecache.go b/libgo/go/runtime/mpagecache.go index 7206e2dbdb7..5bad4f789a1 100644 --- a/libgo/go/runtime/mpagecache.go +++ b/libgo/go/runtime/mpagecache.go @@ -143,7 +143,7 @@ func (p *pageAlloc) allocToCache() pageCache { if addr == 0 { // We failed to find adequate free space, so mark the searchAddr as OoM // and return an empty pageCache. - p.searchAddr = maxSearchAddr + p.searchAddr = maxSearchAddr() return pageCache{} } ci := chunkIndex(addr)