+2015-12-17 Pierre-Marie de Rodat <derodat@adacore.com>
+
+ * langhooks.h (struct lang_hooks_for_types): Add a
+ get_debug_type field.
+ * langhooks-def.h (LANG_HOOKS_GET_DEBUG_TYPE): New macro.
+ (LANG_HOOKS_FOR_TYPES_INITIALIZER): Initialize the
+ get_debug_type field.
+ * dwarf2out.h (struct array_descr_info): Add an array-wide
+ stride field.
+ * dwarf2out.c (modified_type_die): Invoke the get_debug_type
+ language hook, process its result instead, if any.
+ (gen_descr_array_type_die): Add array-wide stride processing.
+
2015-12-17 Pierre-Marie de Rodat <derodat@adacore.com>
* debug.h (struct gcc_debug_hooks): Add a new size_function
+2015-12-17 Pierre-Marie de Rodat <derodat@adacore.com>
+
+ * gcc-interface/ada-tree.h (struct lang_type): Rename the t
+ field as t1 and add a t2 one.
+ (get_lang_specific): New.
+ (GET_TYPE_LANG_SPECIFIC): Refactor to use get_lang_specific.
+ (SET_TYPE_LANG_SPECIFIC): Likewise.
+ (GET_TYPE_LANG_SPECIFIC2): New macro.
+ (SET_TYPE_LANG_SPECIFIC2): New macro.
+ (TYPE_DEBUG_TYPE): New macro.
+ (SET_TYPE_DEBUG_TYPE): New macro.
+ * gcc-interface/decl.c (gnat_to_gnu_entity): When
+ -fgnat-encodings=minimal, set padding types' debug type to the
+ padded one (i.e. strip ___PAD GNAT encodings) and set
+ constrained record subtypes's debug type to the base type.
+ * gcc-interface/misc.c (gnat_print_type): Print debug types.
+ (gnat_get_debug_type): New.
+ (gnat_get_array_descr_info): When -fgnat-encodings=minimal, set
+ a byte stride for arrays that contain a type whose debug type
+ has variable length.
+ (LANG_HOOKS_GET_DEBUG_TYPE): Redefine macro to implement the
+ debug type language hook.
+ * gcc-interface/utils.c (maybe_pad_type): When
+ -fgnat-encodings=minimal, set padding types' debug type to the
+ padded one. Restore XVZ variables creation when
+ -fgnat-encodings-minimal and use them to hold padding types'
+ byte size. For library-level padding types, share this variable
+ across translation units. Tag XVZ variables as artificial.
+
2015-12-17 Pierre-Marie de Rodat <derodat@adacore.com>
* gcc-interface/decl.c (gnat_to_gnu_entity): Disable ___XVS GNAT
};
/* Ada uses the lang_decl and lang_type fields to hold a tree. */
-struct GTY(()) lang_type { tree t; };
+struct GTY(()) lang_type { tree t1; tree t2; };
struct GTY(()) lang_decl { tree t; };
-/* Macros to get and set the tree in TYPE_LANG_SPECIFIC. */
+extern struct lang_type *get_lang_specific (tree node);
+
+/* Macros to get and set the trees in TYPE_LANG_SPECIFIC. */
#define GET_TYPE_LANG_SPECIFIC(NODE) \
- (TYPE_LANG_SPECIFIC (NODE) ? TYPE_LANG_SPECIFIC (NODE)->t : NULL_TREE)
+ (TYPE_LANG_SPECIFIC (NODE) ? TYPE_LANG_SPECIFIC (NODE)->t1 : NULL_TREE)
-#define SET_TYPE_LANG_SPECIFIC(NODE, X) \
-do { \
- tree tmp = (X); \
- if (!TYPE_LANG_SPECIFIC (NODE)) \
- TYPE_LANG_SPECIFIC (NODE) \
- = ggc_alloc<struct lang_type> (); \
- TYPE_LANG_SPECIFIC (NODE)->t = tmp; \
-} while (0)
+#define SET_TYPE_LANG_SPECIFIC(NODE, X) (get_lang_specific (NODE)->t1 = (X))
+
+#define GET_TYPE_LANG_SPECIFIC2(NODE) \
+ (TYPE_LANG_SPECIFIC (NODE) ? TYPE_LANG_SPECIFIC (NODE)->t2 : NULL_TREE)
+
+#define SET_TYPE_LANG_SPECIFIC2(NODE, X) (get_lang_specific (NODE)->t2 = (X))
/* Macros to get and set the tree in DECL_LANG_SPECIFIC. */
#define GET_DECL_LANG_SPECIFIC(NODE) \
#define SET_TYPE_ADA_SIZE(NODE, X) \
SET_TYPE_LANG_SPECIFIC (RECORD_OR_UNION_CHECK (NODE), X)
+/* For types with TYPE_CAN_HAVE_DEBUG_TYPE_P, this is the type to use in
+ debugging information. */
+#define TYPE_DEBUG_TYPE(NODE) \
+ GET_TYPE_LANG_SPECIFIC2(NODE)
+#define SET_TYPE_DEBUG_TYPE(NODE, X) \
+ SET_TYPE_LANG_SPECIFIC2(NODE, X)
/* Flags added to decl nodes. */
gnu_type = make_node (RECORD_TYPE);
TYPE_NAME (gnu_type) = create_concat_name (gnat_entity, "PAD");
+ if (gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
+ SET_TYPE_DEBUG_TYPE (gnu_type, gnu_field_type);
TYPE_PACKED (gnu_type) = 1;
TYPE_SIZE (gnu_type) = TYPE_SIZE (gnu_field_type);
TYPE_SIZE_UNIT (gnu_type) = TYPE_SIZE_UNIT (gnu_field_type);
gnu_type = make_node (RECORD_TYPE);
TYPE_NAME (gnu_type) = gnu_entity_name;
+ if (gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
+ SET_TYPE_DEBUG_TYPE (gnu_type, gnu_base_type);
TYPE_PACKED (gnu_type) = TYPE_PACKED (gnu_base_type);
TYPE_REVERSE_STORAGE_ORDER (gnu_type)
= Reverse_Storage_Order (gnat_entity);
default:
break;
}
+
+ if (TYPE_DEBUG_TYPE (node) != NULL_TREE)
+ print_node_brief (file, "debug type", TYPE_DEBUG_TYPE (node),
+ indent + 4);
}
/* Return the name to be printed for DECL. */
return NULL_TREE;
}
+/* Return the type to used for debugging information instead of TYPE, if any.
+ NULL_TREE if TYPE is fine. */
+
+static tree
+gnat_get_debug_type (const_tree type)
+{
+ return TYPE_DEBUG_TYPE (type);
+}
+
/* Return true if types T1 and T2 are identical for type hashing purposes.
Called only after doing all language independent checks. At present,
this function is only called when both types are FUNCTION_TYPE. */
info->element_type = TREE_TYPE (last_dimen);
+ /* When arrays contain dynamically-sized elements, we usually wrap them in
+ padding types, or we create constrained types for them. Then, if such
+ types are stripped in the debugging information output, the debugger needs
+ a way to know the size that is reserved for each element. This is why we
+ emit a stride in such situations. */
+ if (gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
+ {
+ tree source_element_type = info->element_type;
+
+ while (1)
+ {
+ if (TYPE_DEBUG_TYPE (source_element_type) != NULL_TREE)
+ source_element_type = TYPE_DEBUG_TYPE (source_element_type);
+ else if (TYPE_IS_PADDING_P (source_element_type))
+ source_element_type
+ = TREE_TYPE (TYPE_FIELDS (source_element_type));
+ else
+ break;
+ }
+
+ if (TREE_CODE (TYPE_SIZE_UNIT (source_element_type)) != INTEGER_CST)
+ {
+ info->stride = TYPE_SIZE_UNIT (info->element_type);
+ info->stride_in_bits = false;
+ }
+ }
+
return true;
}
MARK_TS_TYPED (EXIT_STMT);
}
+/* Return the lang specific structure attached to NODE. Allocate it (cleared)
+ if needed. */
+
+struct lang_type *
+get_lang_specific (tree node)
+{
+ if (!TYPE_LANG_SPECIFIC (node))
+ TYPE_LANG_SPECIFIC (node) = ggc_cleared_alloc<struct lang_type> ();
+ return TYPE_LANG_SPECIFIC (node);
+}
+
/* Definitions for our language-specific hooks. */
#undef LANG_HOOKS_NAME
#define LANG_HOOKS_GET_SUBRANGE_BOUNDS gnat_get_subrange_bounds
#undef LANG_HOOKS_DESCRIPTIVE_TYPE
#define LANG_HOOKS_DESCRIPTIVE_TYPE gnat_descriptive_type
+#undef LANG_HOOKS_GET_DEBUG_TYPE
+#define LANG_HOOKS_GET_DEBUG_TYPE gnat_get_debug_type
#undef LANG_HOOKS_ATTRIBUTE_TABLE
#define LANG_HOOKS_ATTRIBUTE_TABLE gnat_internal_attribute_table
#undef LANG_HOOKS_BUILTIN_FUNCTION
type and name. */
record = make_node (RECORD_TYPE);
TYPE_PADDING_P (record) = 1;
+ if (gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
+ SET_TYPE_DEBUG_TYPE (record, type);
if (Present (gnat_entity))
TYPE_NAME (record) = create_concat_name (gnat_entity, "PAD");
/* Unless debugging information isn't being written for the input type,
write a record that shows what we are a subtype of and also make a
- variable that indicates our size, if still variable. Don't do this if
- asked to output as few encodings as possible. */
- if (gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL
- && TREE_CODE (orig_size) != INTEGER_CST
+ variable that indicates our size, if still variable. */
+ if (TREE_CODE (orig_size) != INTEGER_CST
&& TYPE_NAME (record)
&& TYPE_NAME (type)
&& !(TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
&& TREE_CODE (size) != INTEGER_CST
&& (definition || global_bindings_p ()))
{
+ /* Whether or not gnat_entity comes from source, this XVZ variable is
+ is a compilation artifact. */
size_unit
= create_var_decl (concat_name (name, "XVZ"), NULL_TREE, sizetype,
size_unit, true, global_bindings_p (),
TYPE_SIZE_UNIT (record) = size_unit;
}
- tree marker = make_node (RECORD_TYPE);
- tree orig_name = TYPE_IDENTIFIER (type);
-
- TYPE_NAME (marker) = concat_name (name, "XVS");
- finish_record_type (marker,
- create_field_decl (orig_name,
- build_reference_type (type),
- marker, NULL_TREE, NULL_TREE,
- 0, 0),
- 0, true);
- TYPE_SIZE_UNIT (marker) = size_unit;
-
- add_parallel_type (record, marker);
+ /* There is no need to show what we are a subtype of when outputting as
+ few encodings as possible: regular debugging infomation makes this
+ redundant. */
+ if (gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL)
+ {
+ tree marker = make_node (RECORD_TYPE);
+ tree orig_name = TYPE_IDENTIFIER (type);
+
+ TYPE_NAME (marker) = concat_name (name, "XVS");
+ finish_record_type (marker,
+ create_field_decl (orig_name,
+ build_reference_type (type),
+ marker, NULL_TREE, NULL_TREE,
+ 0, 0),
+ 0, true);
+ TYPE_SIZE_UNIT (marker) = size_unit;
+
+ add_parallel_type (record, marker);
+ }
}
rest_of_record_type_compilation (record);
if (code == ERROR_MARK)
return NULL;
+ if (lang_hooks.types.get_debug_type)
+ {
+ tree debug_type = lang_hooks.types.get_debug_type (type);
+
+ if (debug_type != NULL_TREE && debug_type != type)
+ return modified_type_die (debug_type, cv_quals, context_die);
+ }
+
cv_quals &= cv_qual_mask;
/* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
dw_scalar_form_constant
| dw_scalar_form_exprloc
| dw_scalar_form_reference, &context);
+ if (info->stride)
+ {
+ const enum dwarf_attribute attr
+ = (info->stride_in_bits) ? DW_AT_bit_stride : DW_AT_byte_stride;
+ const int forms
+ = (info->stride_in_bits)
+ ? dw_scalar_form_constant
+ : (dw_scalar_form_constant
+ | dw_scalar_form_exprloc
+ | dw_scalar_form_reference);
+
+ add_scalar_info (array_die, attr, info->stride, forms, &context);
+ }
}
add_gnat_descriptive_type_attribute (array_die, type, context_die);
tree data_location;
tree allocated;
tree associated;
+ tree stride;
+ bool stride_in_bits;
struct array_descr_dimen
{
/* GCC uses sizetype for array indices, so lower_bound and upper_bound
tree bounds_type;
tree lower_bound;
tree upper_bound;
+
+ /* Only Fortran uses more than one dimension for array types. For other
+ languages, the stride can be rather specified for the whole array. */
tree stride;
} dimen[10];
};
#define LANG_HOOKS_DESCRIPTIVE_TYPE NULL
#define LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE reconstruct_complex_type
#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE lhd_enum_underlying_base_type
+#define LANG_HOOKS_GET_DEBUG_TYPE NULL
#define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
LANG_HOOKS_MAKE_TYPE, \
LANG_HOOKS_GET_SUBRANGE_BOUNDS, \
LANG_HOOKS_DESCRIPTIVE_TYPE, \
LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE, \
- LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE \
+ LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE, \
+ LANG_HOOKS_GET_DEBUG_TYPE \
}
/* Declaration hooks. */
type_for_size. Used in dwarf2out.c to add a DW_AT_type base type
reference to a DW_TAG_enumeration. */
tree (*enum_underlying_base_type) (const_tree);
+
+ /* Return a type to use in the debug info instead of TYPE, or NULL_TREE to
+ keep TYPE. This is useful to keep a single "source type" when the
+ middle-end uses specialized types, for instance constrained discriminated
+ types in Ada. */
+ tree (*get_debug_type) (const_tree);
};
/* Language hooks related to decls and the symbol table. */