Commit 7352723b by Eric Botcazou Committed by Eric Botcazou

trans.c (add_decl_expr): Minor tweak.

	* gcc-interface/trans.c (add_decl_expr): Minor tweak.
	* gcc-interface/utils.c (create_var_decl): For an external variable,
	also clear TREE_READONLY in LTO mode if the initializer is not a valid
	constant and set DECL_READONLY_ONCE_ELAB instead.

From-SVN: r238206
parent 833c1dbc
2016-07-11 Eric Botcazou <ebotcazou@adacore.com> 2016-07-11 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/trans.c (add_decl_expr): Minor tweak.
* gcc-interface/utils.c (create_var_decl): For an external variable,
also clear TREE_READONLY in LTO mode if the initializer is not a valid
constant and set DECL_READONLY_ONCE_ELAB instead.
2016-07-11 Eric Botcazou <ebotcazou@adacore.com>
PR ada/71817 PR ada/71817
* adaint.c (__gnat_is_read_accessible_file): Add parentheses. * adaint.c (__gnat_is_read_accessible_file): Add parentheses.
(__gnat_is_write_accessible_file): Likewise. (__gnat_is_write_accessible_file): Likewise.
......
...@@ -8012,7 +8012,7 @@ void ...@@ -8012,7 +8012,7 @@ void
add_decl_expr (tree gnu_decl, Entity_Id gnat_entity) add_decl_expr (tree gnu_decl, Entity_Id gnat_entity)
{ {
tree type = TREE_TYPE (gnu_decl); tree type = TREE_TYPE (gnu_decl);
tree gnu_stmt, gnu_init, t; tree gnu_stmt, gnu_init;
/* If this is a variable that Gigi is to ignore, we may have been given /* If this is a variable that Gigi is to ignore, we may have been given
an ERROR_MARK. So test for it. We also might have been given a an ERROR_MARK. So test for it. We also might have been given a
...@@ -8059,15 +8059,6 @@ add_decl_expr (tree gnu_decl, Entity_Id gnat_entity) ...@@ -8059,15 +8059,6 @@ add_decl_expr (tree gnu_decl, Entity_Id gnat_entity)
&& !initializer_constant_valid_p (gnu_init, && !initializer_constant_valid_p (gnu_init,
TREE_TYPE (gnu_init))))) TREE_TYPE (gnu_init)))))
{ {
/* If GNU_DECL has a padded type, convert it to the unpadded
type so the assignment is done properly. */
if (TYPE_IS_PADDING_P (type))
t = convert (TREE_TYPE (TYPE_FIELDS (type)), gnu_decl);
else
t = gnu_decl;
gnu_stmt = build_binary_op (INIT_EXPR, NULL_TREE, t, gnu_init);
DECL_INITIAL (gnu_decl) = NULL_TREE; DECL_INITIAL (gnu_decl) = NULL_TREE;
if (TREE_READONLY (gnu_decl)) if (TREE_READONLY (gnu_decl))
{ {
...@@ -8075,6 +8066,12 @@ add_decl_expr (tree gnu_decl, Entity_Id gnat_entity) ...@@ -8075,6 +8066,12 @@ add_decl_expr (tree gnu_decl, Entity_Id gnat_entity)
DECL_READONLY_ONCE_ELAB (gnu_decl) = 1; DECL_READONLY_ONCE_ELAB (gnu_decl) = 1;
} }
/* If GNU_DECL has a padded type, convert it to the unpadded
type so the assignment is done properly. */
if (TYPE_IS_PADDING_P (type))
gnu_decl = convert (TREE_TYPE (TYPE_FIELDS (type)), gnu_decl);
gnu_stmt = build_binary_op (INIT_EXPR, NULL_TREE, gnu_decl, gnu_init);
add_stmt_with_node (gnu_stmt, gnat_entity); add_stmt_with_node (gnu_stmt, gnat_entity);
} }
} }
......
...@@ -2430,8 +2430,9 @@ create_var_decl (tree name, tree asm_name, tree type, tree init, ...@@ -2430,8 +2430,9 @@ create_var_decl (tree name, tree asm_name, tree type, tree init,
and may be used for scalars in general but not for aggregates. */ and may be used for scalars in general but not for aggregates. */
tree var_decl tree var_decl
= build_decl (input_location, = build_decl (input_location,
(constant_p && const_decl_allowed_p (constant_p
&& !AGGREGATE_TYPE_P (type)) ? CONST_DECL : VAR_DECL, && const_decl_allowed_p
&& !AGGREGATE_TYPE_P (type) ? CONST_DECL : VAR_DECL),
name, type); name, type);
/* Detect constants created by the front-end to hold 'reference to function /* Detect constants created by the front-end to hold 'reference to function
...@@ -2456,9 +2457,20 @@ create_var_decl (tree name, tree asm_name, tree type, tree init, ...@@ -2456,9 +2457,20 @@ create_var_decl (tree name, tree asm_name, tree type, tree init,
constant initialization and save any variable elaborations for the constant initialization and save any variable elaborations for the
elaboration routine. If we are just annotating types, throw away the elaboration routine. If we are just annotating types, throw away the
initialization if it isn't a constant. */ initialization if it isn't a constant. */
if ((extern_flag && !constant_p) if ((extern_flag && init && !constant_p)
|| (type_annotate_only && init && !TREE_CONSTANT (init))) || (type_annotate_only && init && !TREE_CONSTANT (init)))
init = NULL_TREE; {
init = NULL_TREE;
/* In LTO mode, also clear TREE_READONLY the same way add_decl_expr
would do it if the initializer was not thrown away here, as the
WPA phase requires a consistent view across compilation units. */
if (const_flag && flag_generate_lto)
{
const_flag = false;
DECL_READONLY_ONCE_ELAB (var_decl) = 1;
}
}
/* At the global level, a non-constant initializer generates elaboration /* At the global level, a non-constant initializer generates elaboration
statements. Check that such statements are allowed, that is to say, statements. Check that such statements are allowed, that is to say,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment