trans.c (Identifier_to_gnu): Test Is_Elementary_Type instead of Is_Scalar_Type for...
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 11 Jun 2012 08:54:32 +0000 (08:54 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 11 Jun 2012 08:54:32 +0000 (08:54 +0000)
* 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.

From-SVN: r188380

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

index 031d6616c0646e6bd689e62c8dc97990cfcda596..de1d479203de1adde6b57c7cc7cfdcfeca85f536 100644 (file)
@@ -1,3 +1,10 @@
+2012-06-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * 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.
+
 2012-06-11  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/decl.c (gnat_to_gnu_entity): Do not specifically deal
index d79cd46900dffdfe83fb773cc625a5dad0c8d3ad..6e651f4312352185161a2fbe69b902cfd1621386 100644 (file)
@@ -1019,7 +1019,7 @@ Identifier_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p)
      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, tree *gnu_result_type_p)
      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, tree *gnu_result_type_p)
          = 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,