From patchwork Mon Jun 11 08:50:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 164099 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 40C31B6FA1 for ; Mon, 11 Jun 2012 18:54:57 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1340009697; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:Date:User-Agent:MIME-Version: Content-Type:Message-Id:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=fGOJrkd+Qhi7CToyBmIDrMf5JPA=; b=lQohXMTZ2KE7ZMH TGdKsuMbdsoiaFueDAYeEEJUN+BjFpV/AocJ/6aODsoCsbkuBflTBpam0mM3jEhT ka5n8WVG4RcE5Kz0VRE5OoT6bJSx/T38jr/+iZbaJRLE7+iJhkJ9Np34IGL3i41A ZPJb+jK9zbWyr0BQXpkYw44DPr9k= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Subject:Date:User-Agent:MIME-Version:Content-Type:Message-Id:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=QuvGiQCN4wEu8jKMGu0zIJNj6Os/SgrVR5DJ1jnZd5P+jiPpdz4i1TEyEnG73w yjQsWE13ovHhh/qdmr7j03wUZw4ytS9yBK8WvgBPtZ4TCj/dp1bdkSlHJOSX7RCe Hfu0Z2kxnrufcFSq2Ghp+ACMinjOeoqd+A9vUPFFema3E=; Received: (qmail 23109 invoked by alias); 11 Jun 2012 08:54:53 -0000 Received: (qmail 23094 invoked by uid 22791); 11 Jun 2012 08:54:52 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 11 Jun 2012 08:54:39 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 222A229004F for ; Mon, 11 Jun 2012 10:54:45 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WdlmCH2P2nFI for ; Mon, 11 Jun 2012 10:54:45 +0200 (CEST) Received: from [192.168.1.2] (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id DE95929003A for ; Mon, 11 Jun 2012 10:54:44 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Plug hole with constants used by reference Date: Mon, 11 Jun 2012 10:50:57 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201206111050.57165.ebotcazou@adacore.com> 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 This aligns the processing of constants used by reference in Identifier_to_gnu with that of regular constants; in particular we stop returning the underlying constant if this is the address of a constant and an lvalue is required. Tested on i586-suse-linux, applied on the mainline. 2012-06-11 Eric Botcazou * gcc-interface/trans.c (Identifier_to_gnu): Test Is_Elementary_Type instead of Is_Scalar_Type for a constant with an address clause. Do not return the underlying constant for a constant used by reference if it holds the address of a constant and an lvalue is required. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 188377) +++ gcc-interface/trans.c (working copy) @@ -1019,7 +1019,7 @@ Identifier_to_gnu (Node_Id gnat_node, tr order-of-elaboration issue here. */ gnu_result_type = get_unpadded_type (gnat_temp_type); - /* If this is a non-imported scalar constant with an address clause, + /* If this is a non-imported elementary constant with an address clause, retrieve the value instead of a pointer to be dereferenced unless an lvalue is required. This is generally more efficient and actually required if this is a static expression because it might be used @@ -1028,7 +1028,7 @@ Identifier_to_gnu (Node_Id gnat_node, tr volatile-ness short-circuit here since Volatile constants must be imported per C.6. */ if (Ekind (gnat_temp) == E_Constant - && Is_Scalar_Type (gnat_temp_type) + && Is_Elementary_Type (gnat_temp_type) && !Is_Imported (gnat_temp) && Present (Address_Clause (gnat_temp))) { @@ -1080,7 +1080,10 @@ Identifier_to_gnu (Node_Id gnat_node, tr = convert (build_pointer_type (gnu_result_type), gnu_result); /* If it's a CONST_DECL, return the underlying constant like below. */ - else if (TREE_CODE (gnu_result) == CONST_DECL) + else if (TREE_CODE (gnu_result) == CONST_DECL + && !(DECL_CONST_ADDRESS_P (gnu_result) + && lvalue_required_p (gnat_node, gnu_result_type, true, + true, false))) gnu_result = DECL_INITIAL (gnu_result); /* If it's a renaming pointer and we are at the right binding level,