From patchwork Mon Oct 23 21:14:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 157110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1557736vqx; Mon, 23 Oct 2023 14:15:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGncLaqRgLVhAWDZEKgmakvUvAPpWawqnfa0wWE1XMAMgY38b3yZBzGFkoHLnmoTX0zae/v X-Received: by 2002:a05:622a:242:b0:41e:1f5d:7010 with SMTP id c2-20020a05622a024200b0041e1f5d7010mr3702320qtx.37.1698095713579; Mon, 23 Oct 2023 14:15:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698095713; cv=pass; d=google.com; s=arc-20160816; b=MKWCIs96RyihS2PTy65Q8DzvgD9+00AZcnEUpgGj7qNFYpU9QJmOjor472IpAk+UGd nmRtG7QGsLlEPyJ1Vpr6/KRFrfn4nihUUcRT3HtfuZjLnrMEPFQ7uy1htu4xw6ItmZcE oWl7lXFO8T9G6fF3wVRG3xl2K9AdViXBPL9t2DnaVAiMY8sTYQ+IPcWwL46vH3IDh4fE UYa2GvveAxRN1cgBS02U/mvY6buL5FEPsrteXxSdhxGKjIfQ0xyL1063B6rXMYjaX8vZ LfSjRz2yoQS0bRofqVA8/DCxMo0fj3zZYHeDQRVTTGf4YZir6ul0VXq7H4zyAHG6yGaZ LPiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:message-id:date:from :mime-version:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=peVkfTXoC6YHiIz3wMso4z2t6MwCfEdsXZlGVkvqnuo=; fh=sx1AF6BoRLLvWrm7PiL2RBt/kekZxFGoFwZKL1Ho560=; b=P5M5VwKhFAvLHME5uNch6oWKXJLHrfevyTWAuEAm65YSbli8Oukjml4uFovuEeZJV6 MWmpJW8ayAihdGxC41Hv1PmhOWKgvFlp1K6im9NBCih9g2YJYl3EjArbcSN7syQBOGRH ONy+0kehHlv6ocr/g+pYMWNtxNjIuVfTMkBfu6S/RTtjdDA4TGk5M/XxDl20SDYw3c7u XYB+xxnixPeoXNk/4M1njDSFEwYAE/AQWaQQE7ipn7g9zxIWNScYIEu3FuSFH3GG6u0v Xir0eo3AdWr4Y/EXURW8Ee7t2jcLbLJCQq7meUDji91KBJKkoG8ozVztrfDEc7igdnM4 XK0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@golang-org.20230601.gappssmtp.com header.s=20230601 header.b=BDB1bfTG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=golang.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l8-20020a05622a174800b0041959d7951fsi5977405qtk.581.2023.10.23.14.15.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:15:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@golang-org.20230601.gappssmtp.com header.s=20230601 header.b=BDB1bfTG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=golang.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 025613871039 for ; Mon, 23 Oct 2023 21:15:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by sourceware.org (Postfix) with ESMTPS id 540ED385B537 for ; Mon, 23 Oct 2023 21:14:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 540ED385B537 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=golang.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=golang.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 540ED385B537 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698095682; cv=none; b=phc1b3RsM4Jh5SDGjJQAwpQzT4NqJCvmXHrFAYoUoSrkkrsUuTXEATNVt5t/DtcCNZHR8NBhzNx+mLaySS9foxqj8IQzF7YOvqafuZC4j637EjpowqC/aY+S9bLvCE0TjekexGBuVGez/92pHmQ2viApK5+sxd5NxxBUXaMR4Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698095682; c=relaxed/simple; bh=kXQ6GseOjenEsKRWI2I4Q5YlePm/O/XaL3K6FS13X9U=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=vrjqMSDmxomtsxC5fa/nldhJiNAjt7Tz16ABsBXBw8637fIRYGlbuTSdMbmvS25X610efwUXsy9V1zDJzlwHdYE3zGCSZsAXa8Bj5lZ+PVnw0KIrwvz3UR79avdxAlEAhCR+RoR/OcKMLyZG63dT75fFpATFEg84Rds+OTnTIBI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5a7be88e9ccso39143987b3.2 for ; Mon, 23 Oct 2023 14:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20230601.gappssmtp.com; s=20230601; t=1698095679; x=1698700479; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=peVkfTXoC6YHiIz3wMso4z2t6MwCfEdsXZlGVkvqnuo=; b=BDB1bfTGVTUC5/vdykmsRlJ84Oe6baL5WI7rlpA3BivbflvSlOz4iydvTh15IVY9lO lsTw3bs1zIlPi2luEpnDOrgaDEeW5N52q9p7C6uHIR1s9Khm+eFq+5+507YLd+nNN5mW 9Rbgj8ofGO28A5zJzLt/bBMuJHHGw/pjubo6Me5sQAgkO7sAZypm4gmWP06jveqg2osY tNjBaU+jnEXL0eWunoferj94oEx9K/sRuaggctqSWscXFWfYd4a4hpMQv9zhgzgjCUmF f51AIXSHf+273FIYm7zPP5VXF/gLSNDtP+NWcixaF7/V4ejzFdPklpPeGEuPH3L8WhSD z7hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095679; x=1698700479; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=peVkfTXoC6YHiIz3wMso4z2t6MwCfEdsXZlGVkvqnuo=; b=krv9ApxT5sWe5KoblB/R2sOXzVWai0Ac9AtE3of0A9LDOheD4ws2u3qJSVrziGCvKY SrqDQGVlqUotmSvYlpdXMyxjzkFs2xs7bL4IpyFey120MclvBtEh8IcI0YgLEKeCDSAP Q0lSBjrRepJoyg91uFvZfMmRdA0hN/Z/955HSLQDSoD2b7HkBaCNUTUoJz7KqLuKvV+t dnrHcLqo8G+jWir8Z4nMbOQSOw8oWKdLXNvm5IlX7+/Wi1U1fNFsVP+4PBrNe/k0HeTC bR1aodbCTpTVUth+ndqeDoNtEZYoR5MDjISzOjBkRRwodU09g1sQVxspv9kC3sX7Acpr Ft5g== X-Gm-Message-State: AOJu0Yy/v5R2LywwK7NA/fOPPFzDSDdulS8Oo59XHble0kGAzS93WZ8x ffp6AtMQNqqPyNTFL32MNaxTfK9etbHXokBh6EMvgjYlvXmvQndFTK0= X-Received: by 2002:a81:5e09:0:b0:594:f864:8507 with SMTP id s9-20020a815e09000000b00594f8648507mr10517142ywb.51.1698095679479; Mon, 23 Oct 2023 14:14:39 -0700 (PDT) MIME-Version: 1.0 From: Ian Lance Taylor Date: Mon, 23 Oct 2023 14:14:28 -0700 Message-ID: Subject: Go patch committed: Make xx_constant_value methods non-const To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-10.1 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582410806529088 X-GMAIL-MSGID: 1780582410806529088 This patch to the Go frontend changes the Expression {numeric,string,boolean}_constant_value methods to be non-const. This does not affect anything immediately, but will be useful for later CLs in this series. The only real effect is to Builtin_call_expression::do_export, which remains const and can no longer call numeric_constant_value. But it never needed to call it, as do_export runs after do_lower, and do_lower replaces a constant expression with the actual constant. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 597dba85b3e66a0836dd7442edcc2fda7e0703fc diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index d962c4f5770..35b9cd780da 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -806217827fe30553d535f876f182a9e92f5f648e +3c2a441ef6cafb018bb3cc16f8403ae3d1daf2e1 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/expressions.cc b/gcc/go/gofrontend/expressions.cc index c7b442d3a03..f218731041b 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -846,7 +846,7 @@ class Error_expression : public Expression { return false; } bool - do_numeric_constant_value(Numeric_constant* nc) const + do_numeric_constant_value(Numeric_constant* nc) { nc->set_unsigned_long(NULL, 0); return true; @@ -1992,7 +1992,7 @@ class Boolean_expression : public Expression { return this->val_ == false; } bool - do_boolean_constant_value(bool* val) const + do_boolean_constant_value(bool* val) { *val = this->val_; return true; @@ -2537,7 +2537,7 @@ class Integer_expression : public Expression { return true; } bool - do_numeric_constant_value(Numeric_constant* nc) const; + do_numeric_constant_value(Numeric_constant* nc); Type* do_type(); @@ -2602,7 +2602,7 @@ Integer_expression::do_traverse(Traverse* traverse) // this as a character when appropriate. bool -Integer_expression::do_numeric_constant_value(Numeric_constant* nc) const +Integer_expression::do_numeric_constant_value(Numeric_constant* nc) { if (this->is_character_constant_) nc->set_rune(this->type_, this->val_); @@ -2983,7 +2983,7 @@ class Float_expression : public Expression { return true; } bool - do_numeric_constant_value(Numeric_constant* nc) const + do_numeric_constant_value(Numeric_constant* nc) { nc->set_float(this->type_, this->val_); return true; @@ -3219,7 +3219,7 @@ class Complex_expression : public Expression { return true; } bool - do_numeric_constant_value(Numeric_constant* nc) const + do_numeric_constant_value(Numeric_constant* nc) { nc->set_complex(this->type_, this->val_); return true; @@ -3480,7 +3480,7 @@ Const_expression::do_lower(Gogo* gogo, Named_object*, // Return a numeric constant value. bool -Const_expression::do_numeric_constant_value(Numeric_constant* nc) const +Const_expression::do_numeric_constant_value(Numeric_constant* nc) { if (this->seen_) return false; @@ -3508,7 +3508,7 @@ Const_expression::do_numeric_constant_value(Numeric_constant* nc) const } bool -Const_expression::do_string_constant_value(std::string* val) const +Const_expression::do_string_constant_value(std::string* val) { if (this->seen_) return false; @@ -3523,7 +3523,7 @@ Const_expression::do_string_constant_value(std::string* val) const } bool -Const_expression::do_boolean_constant_value(bool* val) const +Const_expression::do_boolean_constant_value(bool* val) { if (this->seen_) return false; @@ -4180,7 +4180,7 @@ Type_conversion_expression::do_is_static_initializer() const bool Type_conversion_expression::do_numeric_constant_value( - Numeric_constant* nc) const + Numeric_constant* nc) { if (!this->type_->is_numeric_type()) return false; @@ -4192,7 +4192,7 @@ Type_conversion_expression::do_numeric_constant_value( // Return the constant string value if there is one. bool -Type_conversion_expression::do_string_constant_value(std::string* val) const +Type_conversion_expression::do_string_constant_value(std::string* val) { if (this->type_->is_string_type() && this->expr_->type()->is_string_type()) return this->expr_->string_constant_value(val); @@ -4229,7 +4229,7 @@ Type_conversion_expression::do_string_constant_value(std::string* val) const // Return the constant boolean value if there is one. bool -Type_conversion_expression::do_boolean_constant_value(bool* val) const +Type_conversion_expression::do_boolean_constant_value(bool* val) { if (!this->type_->is_boolean_type()) return false; @@ -5141,7 +5141,7 @@ Unary_expression::eval_constant(Operator op, const Numeric_constant* unc, // Return the integral constant value of a unary expression, if it has one. bool -Unary_expression::do_numeric_constant_value(Numeric_constant* nc) const +Unary_expression::do_numeric_constant_value(Numeric_constant* nc) { Numeric_constant unc; if (!this->expr_->numeric_constant_value(&unc)) @@ -5154,7 +5154,7 @@ Unary_expression::do_numeric_constant_value(Numeric_constant* nc) const // Return the boolean constant value of a unary expression, if it has one. bool -Unary_expression::do_boolean_constant_value(bool* val) const +Unary_expression::do_boolean_constant_value(bool* val) { if (this->op_ == OPERATOR_NOT && this->expr_->boolean_constant_value(val)) @@ -6733,7 +6733,7 @@ Binary_expression::operand_address(Statement_inserter* inserter, // Return the numeric constant value, if it has one. bool -Binary_expression::do_numeric_constant_value(Numeric_constant* nc) const +Binary_expression::do_numeric_constant_value(Numeric_constant* nc) { Numeric_constant left_nc; if (!this->left_->numeric_constant_value(&left_nc)) @@ -6749,7 +6749,7 @@ Binary_expression::do_numeric_constant_value(Numeric_constant* nc) const // Return the boolean constant value, if it has one. bool -Binary_expression::do_boolean_constant_value(bool* val) const +Binary_expression::do_boolean_constant_value(bool* val) { bool is_comparison = false; switch (this->op_) @@ -9924,7 +9924,7 @@ Builtin_call_expression::do_is_untyped(Type** ptype) const // Return a numeric constant if possible. bool -Builtin_call_expression::do_numeric_constant_value(Numeric_constant* nc) const +Builtin_call_expression::do_numeric_constant_value(Numeric_constant* nc) { if (this->code_ == BUILTIN_LEN || this->code_ == BUILTIN_CAP) @@ -11230,37 +11230,7 @@ Builtin_call_expression::do_get_backend(Translate_context* context) void Builtin_call_expression::do_export(Export_function_body* efb) const { - Numeric_constant nc; - if (this->numeric_constant_value(&nc)) - { - if (nc.is_int()) - { - mpz_t val; - nc.get_int(&val); - Integer_expression::export_integer(efb, val); - mpz_clear(val); - } - else if (nc.is_float()) - { - mpfr_t fval; - nc.get_float(&fval); - Float_expression::export_float(efb, fval); - mpfr_clear(fval); - } - else if (nc.is_complex()) - { - mpc_t cval; - nc.get_complex(&cval); - Complex_expression::export_complex(efb, cval); - mpc_clear(cval); - } - else - go_unreachable(); - - // A trailing space lets us reliably identify the end of the number. - efb->write_c_string(" "); - } - else if (this->code_ == BUILTIN_ADD || this->code_ == BUILTIN_SLICE) + if (this->code_ == BUILTIN_ADD || this->code_ == BUILTIN_SLICE) { char buf[50]; snprintf(buf, sizeof buf, "%s", efb->unsafe_package_index(), diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index 3b8ae68f500..d5df7244aa1 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -598,19 +598,19 @@ class Expression // If this is not a numeric constant, return false. If it is one, // return true, and set VAL to hold the value. bool - numeric_constant_value(Numeric_constant* val) const + numeric_constant_value(Numeric_constant* val) { return this->do_numeric_constant_value(val); } // If this is not a constant expression with string type, return // false. If it is one, return true, and set VAL to the value. bool - string_constant_value(std::string* val) const + string_constant_value(std::string* val) { return this->do_string_constant_value(val); } // If this is not a constant expression with boolean type, return // false. If it is one, return true, and set VAL to the value. bool - boolean_constant_value(bool* val) const + boolean_constant_value(bool* val) { return this->do_boolean_constant_value(val); } // If this is a const reference expression, return the named @@ -1197,19 +1197,19 @@ class Expression // Return whether this is a constant expression of numeric type, and // set the Numeric_constant to the value. virtual bool - do_numeric_constant_value(Numeric_constant*) const + do_numeric_constant_value(Numeric_constant*) { return false; } // Return whether this is a constant expression of string type, and // set VAL to the value. virtual bool - do_string_constant_value(std::string*) const + do_string_constant_value(std::string*) { return false; } // Return whether this is a constant expression of boolean type, and // set VAL to the value. virtual bool - do_boolean_constant_value(bool*) const + do_boolean_constant_value(bool*) { return false; } // Called by the parser if the value is being discarded. @@ -1532,13 +1532,13 @@ class Const_expression : public Expression { return true; } bool - do_numeric_constant_value(Numeric_constant* nc) const; + do_numeric_constant_value(Numeric_constant* nc); bool - do_string_constant_value(std::string* val) const; + do_string_constant_value(std::string* val); bool - do_boolean_constant_value(bool* val) const; + do_boolean_constant_value(bool* val); Type* do_type(); @@ -1865,7 +1865,7 @@ class String_expression : public Expression { return true; } bool - do_string_constant_value(std::string* val) const + do_string_constant_value(std::string* val) { *val = this->val_; return true; @@ -1967,13 +1967,13 @@ class Type_conversion_expression : public Expression do_is_static_initializer() const; bool - do_numeric_constant_value(Numeric_constant*) const; + do_numeric_constant_value(Numeric_constant*); bool - do_string_constant_value(std::string*) const; + do_string_constant_value(std::string*); bool - do_boolean_constant_value(bool*) const; + do_boolean_constant_value(bool*); Type* do_type() @@ -2169,10 +2169,10 @@ class Unary_expression : public Expression do_is_static_initializer() const; bool - do_numeric_constant_value(Numeric_constant*) const; + do_numeric_constant_value(Numeric_constant*); bool - do_boolean_constant_value(bool*) const; + do_boolean_constant_value(bool*); Type* do_type(); @@ -2329,10 +2329,10 @@ class Binary_expression : public Expression do_is_static_initializer() const; bool - do_numeric_constant_value(Numeric_constant*) const; + do_numeric_constant_value(Numeric_constant*); bool - do_boolean_constant_value(bool*) const; + do_boolean_constant_value(bool*); bool do_discarding_value(); @@ -2806,7 +2806,7 @@ class Builtin_call_expression : public Call_expression do_is_untyped(Type**) const; bool - do_numeric_constant_value(Numeric_constant*) const; + do_numeric_constant_value(Numeric_constant*); bool do_discarding_value();