static int compatible_signatures_p (tree ftype1, tree ftype2);
static void rest_of_type_decl_compilation_no_defer (tree);
+/* Return true if GNAT_ADDRESS is a compile time known value.
+ In particular catch System'To_Address. */
+
+static bool
+compile_time_known_address_p (Node_Id gnat_address)
+{
+ return ((Nkind (gnat_address) == N_Unchecked_Type_Conversion
+ && Compile_Time_Known_Value (Expression (gnat_address)))
+ || Compile_Time_Known_Value (gnat_address));
+}
+
/* Given GNAT_ENTITY, an entity in the incoming GNAT tree, return a
GCC type corresponding to that entity. GNAT_ENTITY is assumed to
refer to an Ada type. */
= build_reference_type_for_mode (gnu_type, ptr_mode, true);
gnu_address = convert (gnu_type, gnu_address);
used_by_ref = true;
- const_flag = !Is_Public (gnat_entity);
+ const_flag = !Is_Public (gnat_entity)
+ || compile_time_known_address_p (Expression (Address_Clause
+ (gnat_entity)));
/* If we don't have an initializing expression for the underlying
variable, the initializing expression for the pointer is the
= build_reference_type_for_mode (gnu_type, ptr_mode, true);
gnu_size = NULL_TREE;
- gnu_expr = NULL_TREE;
/* No point in taking the address of an initializing expression
that isn't going to be used. */
+ gnu_expr = NULL_TREE;
+
+ /* If it has an address clause whose value is known at compile
+ time, make the object a CONST_DECL. This will avoid a
+ useless dereference. */
+ if (Present (Address_Clause (gnat_entity)))
+ {
+ Node_Id gnat_address
+ = Expression (Address_Clause (gnat_entity));
+
+ if (compile_time_known_address_p (gnat_address))
+ {
+ gnu_expr = gnat_to_gnu (gnat_address);
+ const_flag = true;
+ }
+ }
used_by_ref = true;
}
for these. */
if (TREE_CODE (gnu_decl) == CONST_DECL
&& (definition || Sloc (gnat_entity) > Standard_Location)
- && (Is_Public (gnat_entity)
+ && ((Is_Public (gnat_entity)
+ && !Present (Address_Clause (gnat_entity)))
|| optimize == 0
|| Address_Taken (gnat_entity)
|| Is_Aliased (gnat_entity)
gnat_entity);
SET_DECL_CONST_CORRESPONDING_VAR (gnu_decl, gnu_corr_var);
+
+ /* As debugging information will be generated for the variable,
+ do not generate information for the constant. */
+ DECL_IGNORED_P (gnu_decl) = true;
}
/* If this is declared in a block that contains a block with an