Consistently generate debug info for elaboration variables

This makes sure that debug info is generated for elaboration variables,
even if the variables are not generated exclusively for this purpose.

gcc/ada/
	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Named_Integer>: Do
	not pass default value in call to create_var_decl.
	<E_Variable>: Likewise.
	<E_Record_Subtype>: Both pass true for const_flag and false for
	const_decl_allowed_p in call to create_var_decl.
	Small tweaks in the generic record type case.
	(elaborate_expression): Rename need_debug into need_for_debug and
	adjust throughout.
	(elaborate_expression_1): Likewise.  Pass Needs_Debug_Info instead
	of need_for_debug in call to create_var_decl.
	(elaborate_expression_2): Likewise.
	* gcc-interface/utils.c (maybe_pad_type): Pass false for
	const_decl_allowed_p in call to create_var_decl.
This commit is contained in:
Eric Botcazou 2021-05-21 11:19:32 +02:00
parent 4a29b8d627
commit 3553d8c2fe
2 changed files with 40 additions and 36 deletions

View File

@ -622,7 +622,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
= create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type,
gnu_expr, true, Is_Public (gnat_entity),
false, false, false, artificial_p,
debug_info_p, NULL, gnat_entity, true);
debug_info_p, NULL, gnat_entity);
}
break;
@ -1527,7 +1527,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
imported_p || !definition, static_flag,
volatile_flag, artificial_p,
debug_info_p && definition, attr_list,
gnat_entity, true);
gnat_entity);
DECL_BY_REF_P (gnu_decl) = used_by_ref;
DECL_POINTS_TO_READONLY_P (gnu_decl) = used_by_ref && inner_const_flag;
DECL_CAN_NEVER_BE_NULL_P (gnu_decl) = Can_Never_Be_Null (gnat_entity);
@ -3526,9 +3526,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
= create_var_decl (create_concat_name (gnat_entity,
"XVZ"),
NULL_TREE, sizetype, gnu_size_unit,
false, false, false, false, false,
true, debug_info_p,
NULL, gnat_entity);
true, false, false, false, false,
true, true, NULL, gnat_entity, false);
}
/* Or else, if the subtype is artificial and encodings are not
@ -4455,21 +4454,20 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
if (Unknown_RM_Size (gnat_entity) && TYPE_SIZE (gnu_type))
Set_RM_Size (gnat_entity, annotate_value (rm_size (gnu_type)));
/* If we are at global level, GCC will have applied variable_size to
the type, but that won't have done anything. So, if it's not
a constant or self-referential, call elaborate_expression_1 to
make a variable for the size rather than calculating it each time.
Handle both the RM size and the actual size. */
/* If we are at global level, GCC applied variable_size to the size but
this has done nothing. So, if it's not constant or self-referential,
call elaborate_expression_1 to make a variable for it rather than
calculating it each time. */
if (TYPE_SIZE (gnu_type)
&& !TREE_CONSTANT (TYPE_SIZE (gnu_type))
&& !CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type))
&& global_bindings_p ())
{
tree size = TYPE_SIZE (gnu_type);
tree orig_size = TYPE_SIZE (gnu_type);
TYPE_SIZE (gnu_type)
= elaborate_expression_1 (size, gnat_entity, "SIZE", definition,
false);
= elaborate_expression_1 (TYPE_SIZE (gnu_type), gnat_entity,
"SIZE", definition, false);
/* ??? For now, store the size as a multiple of the alignment in
bytes so that we can see the alignment from the tree. */
@ -4482,7 +4480,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
may not be marked by the call to create_type_decl below. */
MARK_VISITED (TYPE_SIZE_UNIT (gnu_type));
if (TREE_CODE (gnu_type) == RECORD_TYPE)
/* For a record type, deal with the variant part, if any, and handle
the Ada size as well. */
if (RECORD_OR_UNION_TYPE_P (gnu_type))
{
tree variant_part = get_variant_part (gnu_type);
tree ada_size = TYPE_ADA_SIZE (gnu_type);
@ -4535,7 +4535,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
DECL_SIZE_UNIT (variant_part) = TYPE_SIZE_UNIT (union_type);
}
if (operand_equal_p (ada_size, size, 0))
if (operand_equal_p (ada_size, orig_size, 0))
ada_size = TYPE_SIZE (gnu_type);
else
ada_size
@ -6724,12 +6724,12 @@ prepend_attributes (struct attrib **attr_list, Entity_Id gnat_entity)
if a variable needs to be created and DEFINITION is true if this is done
for a definition of GNAT_ENTITY. If NEED_VALUE is true, we need a result;
otherwise, we are just elaborating the expression for side-effects. If
NEED_DEBUG is true, we need a variable for debugging purposes even if it
isn't needed for code generation. */
NEED_FOR_DEBUG is true, we need a variable for debugging purposes even
if it isn't needed for code generation. */
static tree
elaborate_expression (Node_Id gnat_expr, Entity_Id gnat_entity, const char *s,
bool definition, bool need_value, bool need_debug)
bool definition, bool need_value, bool need_for_debug)
{
tree gnu_expr;
@ -6747,12 +6747,12 @@ elaborate_expression (Node_Id gnat_expr, Entity_Id gnat_entity, const char *s,
return NULL_TREE;
/* If it's a static expression, we don't need a variable for debugging. */
if (need_debug && Compile_Time_Known_Value (gnat_expr))
need_debug = false;
if (need_for_debug && Compile_Time_Known_Value (gnat_expr))
need_for_debug = false;
/* Otherwise, convert this tree to its GCC equivalent and elaborate it. */
gnu_expr = elaborate_expression_1 (gnat_to_gnu (gnat_expr), gnat_entity, s,
definition, need_debug);
definition, need_for_debug);
/* Save the expression in case we try to elaborate this entity again. Since
it's not a DECL, don't check it. Don't save if it's a discriminant. */
@ -6766,7 +6766,7 @@ elaborate_expression (Node_Id gnat_expr, Entity_Id gnat_entity, const char *s,
static tree
elaborate_expression_1 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
bool definition, bool need_debug)
bool definition, bool need_for_debug)
{
const bool expr_public_p = Is_Public (gnat_entity);
const bool expr_global_p = expr_public_p || global_bindings_p ();
@ -6814,38 +6814,42 @@ elaborate_expression_1 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
/* If the GNAT encodings are not used, we don't need a variable for debug
info purposes if the expression is a constant or another variable, but
we need to be careful because we do not generate debug info for external
we must be careful because we do not generate debug info for external
variables so DECL_IGNORED_P is not stable across units. */
if (need_debug
if (need_for_debug
&& gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL
&& (TREE_CONSTANT (gnu_expr)
|| (!expr_public_p
&& DECL_P (gnu_expr)
&& !DECL_IGNORED_P (gnu_expr))))
need_debug = false;
need_for_debug = false;
/* Now create it, possibly only for debugging purposes. */
if (use_variable || need_debug)
if (use_variable || need_for_debug)
{
/* The following variable creation can happen when processing the body
of subprograms that are defined out of the extended main unit and
of subprograms that are defined outside of the extended main unit and
inlined. In this case, we are not at the global scope, and thus the
new variable must not be tagged "external", as we used to do here as
soon as DEFINITION was false. */
soon as DEFINITION was false. And note that we test Needs_Debug_Info
here instead of NEED_FOR_DEBUG because, once the variable is created,
whether or not debug information is generated for it is orthogonal to
the reason why it was created in the first place. */
tree gnu_decl
= create_var_decl (create_concat_name (gnat_entity, s), NULL_TREE,
TREE_TYPE (gnu_expr), gnu_expr, true,
expr_public_p, !definition && expr_global_p,
expr_global_p, false, true, need_debug,
NULL, gnat_entity);
expr_global_p, false, true,
Needs_Debug_Info (gnat_entity),
NULL, gnat_entity, false);
/* Using this variable at debug time (if need_debug is true) requires a
proper location. The back-end will compute a location for this
/* Using this variable for debug (if need_for_debug is true) requires
a proper location. The back-end will compute a location for this
variable only if the variable is used by the generated code.
Returning the variable ensures the caller will use it in generated
code. Note that there is no need for a location if the debug info
contains an integer constant. */
if (use_variable || (need_debug && !TREE_CONSTANT (gnu_expr)))
if (use_variable || (need_for_debug && !TREE_CONSTANT (gnu_expr)))
return gnu_decl;
}
@ -6856,7 +6860,7 @@ elaborate_expression_1 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
static tree
elaborate_expression_2 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
bool definition, bool need_debug, unsigned int align)
bool definition, bool need_for_debug, unsigned int align)
{
tree unit_align = size_int (align / BITS_PER_UNIT);
return
@ -6865,7 +6869,7 @@ elaborate_expression_2 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
gnu_expr,
unit_align),
gnat_entity, s, definition,
need_debug),
need_for_debug),
unit_align);
}

View File

@ -1637,7 +1637,7 @@ maybe_pad_type (tree type, tree size, unsigned int align,
= create_var_decl (concat_name (name, "XVZ"), NULL_TREE, sizetype,
size_unit, true, global_bindings_p (),
!definition && global_bindings_p (), false,
false, true, true, NULL, gnat_entity);
false, true, true, NULL, gnat_entity, false);
TYPE_SIZE_UNIT (record) = size_unit;
}