From patchwork Sat Jun 18 10:11:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 100910 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 418A5B7019 for ; Sat, 18 Jun 2011 20:20:06 +1000 (EST) Received: (qmail 16379 invoked by alias); 18 Jun 2011 10:20:02 -0000 Received: (qmail 16307 invoked by uid 22791); 18 Jun 2011 10:20:01 -0000 X-SWARE-Spam-Status: No, hits=-1.9 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; Sat, 18 Jun 2011 10:19:45 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 38306CB050D for ; Sat, 18 Jun 2011 12:19:44 +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 7qnq-ldXKCKj for ; Sat, 18 Jun 2011 12:19:41 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id B479ACB0255 for ; Sat, 18 Jun 2011 12:19:40 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix compilation error on constant passed as memory operand to Asm Date: Sat, 18 Jun 2011 12:11:34 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201106181211.34380.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 prevents the compiler from rejecting a constant passed as memory operand to an Asm statement. While this may seem to be a questionable construct, it can be generated by the front-end in specific cases. Tested on i586-suse-linux, applied on the mainline. 2011-06-18 Eric Botcazou * einfo.ads (Address_Taken): Document use for the second argument of Asm_Input and Asm_Output attributes. * sem_attr.adb (Analyze_Attribute) : If the second argument is an entity name, then set Address_Taken on it. : Likewise. * gcc-interface/trans.c (lvalue_required_for_attribute_p): Handle the Attr_Asm_Input and Attr_Asm_Output attributes explicitly. (gnat_to_gnu) : If an operand is going to end up in memory and is a CONST_DECL, retrieve its corresponding VAR_DECL. 2011-06-18 Eric Botcazou * gnat.dg/constant3.adb: New test. Index: einfo.ads =================================================================== --- einfo.ads (revision 175136) +++ einfo.ads (working copy) @@ -380,9 +380,11 @@ package Einfo is -- Address_Taken (Flag104) -- Present in all entities. Set if the Address or Unrestricted_Access -- attribute is applied directly to the entity, i.e. the entity is the --- entity of the prefix of the attribute reference. Used by Gigi to --- make sure that the address can be meaningfully taken, and also in --- the case of subprograms to control output of certain warnings. +-- entity of the prefix of the attribute reference. Also set if the +-- entity is the second argument of an Asm_Input or Asm_Output attribute, +-- as the construct may entail taking its address. Used by Gigi to make +-- sure that the address can be meaningfully taken, and also in the case +-- of subprograms to control output of certain warnings. -- Aft_Value (synthesized) -- Applies to fixed and decimal types. Computes a universal integer Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 175136) +++ gcc-interface/trans.c (working copy) @@ -706,6 +706,8 @@ lvalue_required_for_attribute_p (Node_Id case Attr_First_Bit: case Attr_Last_Bit: case Attr_Bit: + case Attr_Asm_Input: + case Attr_Asm_Output: default: return 1; } @@ -5489,9 +5491,15 @@ gnat_to_gnu (Node_Id gnat_node) mark it addressable. Note that we don't test allows_mem like in the input case below; this is modelled on the C front-end. */ - if (!allows_reg - && !gnat_mark_addressable (output)) - output = error_mark_node; + if (!allows_reg) + { + STRIP_NOPS (output); + if (TREE_CODE (output) == CONST_DECL + && DECL_CONST_CORRESPONDING_VAR (output)) + output = DECL_CONST_CORRESPONDING_VAR (output); + if (!gnat_mark_addressable (output)) + output = error_mark_node; + } } else output = error_mark_node; @@ -5511,9 +5519,15 @@ gnat_to_gnu (Node_Id gnat_node) { /* If the operand is going to end up in memory, mark it addressable. */ - if (!allows_reg && allows_mem - && !gnat_mark_addressable (input)) - input = error_mark_node; + if (!allows_reg && allows_mem) + { + STRIP_NOPS (input); + if (TREE_CODE (input) == CONST_DECL + && DECL_CONST_CORRESPONDING_VAR (input)) + input = DECL_CONST_CORRESPONDING_VAR (input); + if (!gnat_mark_addressable (input)) + input = error_mark_node; + } } else input = error_mark_node; Index: sem_attr.adb =================================================================== --- sem_attr.adb (revision 175136) +++ sem_attr.adb (working copy) @@ -2243,6 +2243,13 @@ package body Sem_Attr is when Attribute_Asm_Input => Check_Asm_Attribute; + + -- The back-end may need to take the address of E2 + + if Is_Entity_Name (E2) then + Set_Address_Taken (Entity (E2)); + end if; + Set_Etype (N, RTE (RE_Asm_Input_Operand)); ---------------- @@ -2263,6 +2270,13 @@ package body Sem_Attr is end if; Note_Possible_Modification (E2, Sure => True); + + -- The back-end may need to take the address of E2 + + if Is_Entity_Name (E2) then + Set_Address_Taken (Entity (E2)); + end if; + Set_Etype (N, RTE (RE_Asm_Output_Operand)); ---------------