trans.c (Attribute_to_gnu): Do not strip conversions around prefixes that are not...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 5 Sep 2017 09:22:21 +0000 (09:22 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 5 Sep 2017 09:22:21 +0000 (09:22 +0000)
* gcc-interface/trans.c (Attribute_to_gnu) <Attr_Address>: Do not strip
conversions around prefixes that are not references.

From-SVN: r251704

gcc/ada/ChangeLog
gcc/ada/gcc-interface/trans.c

index 0dbc77918de8549f24c5f69b4dac90b465967244..cce0e41dff0dbd91c88771c71c288caf2195211f 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/trans.c (Attribute_to_gnu) <Attr_Address>: Do not strip
+       conversions around prefixes that are not references.
+
 2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/utils.c (unchecked_convert): When the result type is a
index 270bf7a49dc10cb115dcf71be5f73365def48770..518016dc39014ec72e7103f288a4506329ab932b 100644 (file)
@@ -1629,10 +1629,14 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
 
     case Attr_Address:
     case Attr_Unrestricted_Access:
-      /* Conversions don't change addresses but can cause us to miss the
-        COMPONENT_REF case below, so strip them off.  */
-      gnu_prefix = remove_conversions (gnu_prefix,
-                                      !Must_Be_Byte_Aligned (gnat_node));
+      /* Conversions don't change the address of references but can cause
+        build_unary_op to miss the references below, so strip them off.
+        On the contrary, if the address-of operation causes a temporary
+        to be created, then it must be created with the proper type.  */
+      gnu_expr = remove_conversions (gnu_prefix,
+                                    !Must_Be_Byte_Aligned (gnat_node));
+      if (REFERENCE_CLASS_P (gnu_expr))
+       gnu_prefix = gnu_expr;
 
       /* If we are taking 'Address of an unconstrained object, this is the
         pointer to the underlying array.  */