From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30753 invoked by alias); 15 May 2012 23:05:00 -0000 Received: (qmail 30742 invoked by uid 22791); 15 May 2012 23:04:59 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,T_RP_MATCHES_RCVD,T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from mail-pz0-f47.google.com (HELO mail-pz0-f47.google.com) (209.85.210.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 May 2012 23:04:40 +0000 Received: by dalh21 with SMTP id h21so147754dal.20 for ; Tue, 15 May 2012 16:04:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=pipsu2uqdOGIG0KAdBKepo2Zmdkjo1LAndYTAABdh8s=; b=Mw9AxRANmSfeK6UxmklX5v1F0scFoDXfZ98RPHk2mrSeOdt+2zDmUCp1d0ZxSYE7qe mLxGtmn6eLhd8nCvzehT5XfxrA0wRTjy5vlyx87Le1VUtgdal1N5gzR9St3AsF2fBog6 vo3GRV+XoD6J8rfTk4nIO4gXq6xspYENsK621SEtKeEvu26UV160a8v3oBW3fqvm3ju1 Typdp1R1nWeETCq0pVyFmoPlavYsqEuyzDl12ftvqvEkkx0saIkwhz6Qzppi+FnE1z89 hGTtknEsjgBkJK7FWrat2i4pVtpS7JqCER1eNvrIXVhlfjkmliCJVMjopJjDFv3+KSyF NhYg== Received: by 10.68.233.73 with SMTP id tu9mr10237541pbc.1.1337123080420; Tue, 15 May 2012 16:04:40 -0700 (PDT) Received: by 10.68.233.73 with SMTP id tu9mr10237522pbc.1.1337123080299; Tue, 15 May 2012 16:04:40 -0700 (PDT) Received: from coign.google.com ([2620:0:1000:2404:224:d7ff:fe8f:f634]) by mx.google.com with ESMTPS id pu5sm3243391pbc.28.2012.05.15.16.04.39 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 May 2012 16:04:39 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Fix taking address of constant outside function Date: Tue, 15 May 2012 23:05:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Gm-Message-State: ALoCoQk6g9rQISTJajexud8FbOAtHMdOjdPLq34OEvnljQL9cjzGcYLlQeTf+YQ0SKaaZloMVjiuHyeJBSTJQX8QE+AIiMa/RMSPyVJ0SN8avtjR5vjx5t92PGQn/UhYjAjtJtXkJjHb253Xta4iy7mXvS8/cuuiag== X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-05/txt/msg01063.txt.bz2 --=-=-= Content-length: 248 This patch to the Go frontend extends the code I committed earlier today for taking the address of a constant to work outside of a function. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.7 branch. Ian --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=foo.patch Content-Description: patch Content-length: 2089 diff -r f37debbb3806 go/expressions.cc --- a/go/expressions.cc Tue May 15 15:29:37 2012 -0700 +++ b/go/expressions.cc Tue May 15 15:45:22 2012 -0700 @@ -4048,15 +4048,46 @@ && TREE_CODE(expr) != INDIRECT_REF && TREE_CODE(expr) != COMPONENT_REF) { - tree tmp = create_tmp_var(TREE_TYPE(expr), get_name(expr)); - DECL_IGNORED_P(tmp) = 1; - DECL_INITIAL(tmp) = expr; - TREE_ADDRESSABLE(tmp) = 1; - return build2_loc(loc.gcc_location(), COMPOUND_EXPR, - build_pointer_type(TREE_TYPE(expr)), - build1_loc(loc.gcc_location(), DECL_EXPR, - void_type_node, tmp), - build_fold_addr_expr_loc(loc.gcc_location(), tmp)); + if (current_function_decl != NULL) + { + tree tmp = create_tmp_var(TREE_TYPE(expr), get_name(expr)); + DECL_IGNORED_P(tmp) = 1; + DECL_INITIAL(tmp) = expr; + TREE_ADDRESSABLE(tmp) = 1; + return build2_loc(loc.gcc_location(), COMPOUND_EXPR, + build_pointer_type(TREE_TYPE(expr)), + build1_loc(loc.gcc_location(), DECL_EXPR, + void_type_node, tmp), + build_fold_addr_expr_loc(loc.gcc_location(), + tmp)); + } + else + { + tree tmp = build_decl(loc.gcc_location(), VAR_DECL, + create_tmp_var_name("A"), TREE_TYPE(expr)); + DECL_EXTERNAL(tmp) = 0; + TREE_PUBLIC(tmp) = 0; + TREE_STATIC(tmp) = 1; + DECL_ARTIFICIAL(tmp) = 1; + TREE_ADDRESSABLE(tmp) = 1; + tree make_tmp; + if (!TREE_CONSTANT(expr)) + make_tmp = fold_build2_loc(loc.gcc_location(), INIT_EXPR, + void_type_node, tmp, expr); + else + { + TREE_READONLY(tmp) = 1; + TREE_CONSTANT(tmp) = 1; + DECL_INITIAL(tmp) = expr; + make_tmp = NULL_TREE; + } + rest_of_decl_compilation(tmp, 1, 0); + tree addr = build_fold_addr_expr_loc(loc.gcc_location(), tmp); + if (make_tmp == NULL_TREE) + return addr; + return build2_loc(loc.gcc_location(), COMPOUND_EXPR, + TREE_TYPE(addr), make_tmp, addr); + } } return build_fold_addr_expr_loc(loc.gcc_location(), expr); --=-=-=--