From: Eric Botcazou Date: Sat, 18 Jun 2011 10:18:38 +0000 (+0000) Subject: einfo.ads (Address_Taken): Document use for the second argument of Asm_Input and... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7e4680c1a2cf543559a1db79368a2d476f1c233c;p=gcc.git einfo.ads (Address_Taken): Document use for the second argument of Asm_Input and Asm_Output attributes. * 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. From-SVN: r175171 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index b4d5a67e621..b3db7a928c3 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,4 +1,16 @@ -2010-06-16 Joern Rennecke +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-16 Joern Rennecke PR middle-end/46500 * gcc-interface/decl.c (gnat_to_gnu_param): Use pack_cumulative_args. diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 051688ae376..577b208f436 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -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 diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index ca47e9347de..8e949a89edc 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -706,6 +706,8 @@ lvalue_required_for_attribute_p (Node_Id gnat_node) 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; diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index b7b4f2f6319..b2c7a835674 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -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)); --------------- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d1469b6d4e1..dcd49190075 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-06-18 Eric Botcazou + + * gnat.dg/constant3.adb: New test. + 2011-06-18 Janne Blomqvist PR libfortran/48296 @@ -75,8 +79,7 @@ 2011-06-16 Martin Jambor PR tree-optimization/49343 - * gnat.dg/discr31.adb: New test. - * gnat.dg/discr31.ads: Likewise. + * gnat.dg/discr31.ad[sb]: New test. 2011-06-16 Rainer Orth diff --git a/gcc/testsuite/gnat.dg/constant3.adb b/gcc/testsuite/gnat.dg/constant3.adb new file mode 100644 index 00000000000..5ca1792fbd2 --- /dev/null +++ b/gcc/testsuite/gnat.dg/constant3.adb @@ -0,0 +1,21 @@ +-- { dg-do compile } +-- { dg-options "-O" } + +with System.Machine_code; use System.Machine_code; + +procedure Constant3 is + + c : Integer := -1; + r : Integer; + + procedure Conv (res : out Integer; v : Integer) is + v1 : constant Integer := v; + begin + Asm ("", Integer'Asm_output ("=m", res), Integer'Asm_input("m", v1)); + end; + + pragma Inline_Always (Conv); + +begin + Conv (r, c); +end;