}
}
- /* For the declaration of a type, set its name if it either is not already
+ /* For the declaration of a type, set its name either if it isn't already
set or if the previous type name was not derived from a source name.
We'd rather have the type named with a real name and all the pointer
- types to the same object have the same POINTER_TYPE node. Code in the
- equivalent function of c-decl.c makes a copy of the type node here, but
- that may cause us trouble with incomplete types. We make an exception
- for fat pointer types because the compiler automatically builds them
- for unconstrained array types and the debugger uses them to represent
- both these and pointers to these. */
+ types to the same object have the same node, except when the names are
+ both derived from source names. */
if (TREE_CODE (decl) == TYPE_DECL && DECL_NAME (decl))
{
tree t = TREE_TYPE (decl);
- if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL))
+ if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
+ && (TREE_CODE (t) != POINTER_TYPE || DECL_ARTIFICIAL (decl)))
{
- /* Array and pointer types aren't "tagged" types so we force the
- type to be associated with its typedef in the DWARF back-end,
- in order to make sure that the latter is always preserved. */
- if (!DECL_ARTIFICIAL (decl)
- && (TREE_CODE (t) == ARRAY_TYPE
- || TREE_CODE (t) == POINTER_TYPE))
+ /* Array types aren't "tagged" types so we force the type to be
+ associated with its typedef in the DWARF back-end, in order to
+ make sure that the latter is always preserved. We used to do the
+ same for pointer types, but to have consistent DWARF output we now
+ create copies for DECL_ORIGINAL_TYPE just like the C front-end
+ does in c-common.c:set_underlying_type. */
+ if (!DECL_ARTIFICIAL (decl) && TREE_CODE (t) == ARRAY_TYPE)
{
tree tt = build_distinct_type_copy (t);
if (TREE_CODE (t) == POINTER_TYPE)
TYPE_NEXT_PTR_TO (t) = tt;
- TYPE_NAME (tt) = DECL_NAME (decl);
+ /* Array types need to have a name so that they can be related to
+ their GNAT encodings. */
+ if (TREE_CODE (t) == ARRAY_TYPE)
+ TYPE_NAME (tt) = DECL_NAME (decl);
defer_or_set_type_context (tt,
DECL_CONTEXT (decl),
deferred_decl_context);
DECL_ORIGINAL_TYPE (decl) = tt;
}
}
- else if (TYPE_IS_FAT_POINTER_P (t))
+ else if (!DECL_ARTIFICIAL (decl)
+ && (TREE_CODE (t) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (t)))
{
- /* We need a variant for the placeholder machinery to work. */
- tree tt = build_variant_type_copy (t);
+ tree tt;
+ /* ??? We need a variant for the placeholder machinery to work. */
+ if (TYPE_IS_FAT_POINTER_P (t))
+ tt = build_variant_type_copy (t);
+ else
+ tt = build_distinct_type_copy (t);
+ if (TREE_CODE (t) == POINTER_TYPE)
+ TYPE_NEXT_PTR_TO (t) = tt;
TYPE_NAME (tt) = decl;
defer_or_set_type_context (tt,
DECL_CONTEXT (decl),
deferred_decl_context);
TREE_USED (tt) = TREE_USED (t);
TREE_TYPE (decl) = tt;
- if (DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
+ if (TYPE_NAME (t) != NULL_TREE
+ && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
+ && DECL_ORIGINAL_TYPE (TYPE_NAME (t)))
DECL_ORIGINAL_TYPE (decl) = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
else
DECL_ORIGINAL_TYPE (decl) = t;
- DECL_ARTIFICIAL (decl) = 0;
t = NULL_TREE;
}
- else if (DECL_ARTIFICIAL (TYPE_NAME (t)) && !DECL_ARTIFICIAL (decl))
+ else if (TYPE_NAME (t) != NULL_TREE
+ && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
+ && DECL_ARTIFICIAL (TYPE_NAME (t)) && !DECL_ARTIFICIAL (decl))
;
else
t = NULL_TREE;
/* Propagate the name to all the anonymous variants. This is needed
- for the type qualifiers machinery to work properly. Also propagate
- the context to them. Note that the context will be propagated to all
- parallel types too thanks to gnat_set_type_context. */
+ for the type qualifiers machinery to work properly (see
+ check_qualified_type). Also propagate the context to them. Note that
+ the context will be propagated to all parallel types too thanks to
+ gnat_set_type_context. */
if (t)
for (t = TYPE_MAIN_VARIANT (t); t; t = TYPE_NEXT_VARIANT (t))
if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL))
/* Add this decl to the current binding level. */
gnat_pushdecl (type_decl, gnat_node);
- /* If we're naming the type, equate the TYPE_STUB_DECL to the name.
- This causes the name to be also viewed as a "tag" by the debug
- back-end, with the advantage that no DW_TAG_typedef is emitted
- for artificial "tagged" types in DWARF. */
- if (!named)
+ /* If we're naming the type, equate the TYPE_STUB_DECL to the name. This
+ causes the name to be also viewed as a "tag" by the debug back-end, with
+ the advantage that no DW_TAG_typedef is emitted for artificial "tagged"
+ types in DWARF.
+
+ Note that if "type" is used as a DECL_ORIGINAL_TYPE, it may be referenced
+ from multiple contexts, and "type_decl" references a copy of it: in such a
+ case, do not mess TYPE_STUB_DECL: we do not want to re-use the TYPE_DECL
+ with the mechanism above. */
+ if (!named && type != DECL_ORIGINAL_TYPE (type_decl))
TYPE_STUB_DECL (type) = type_decl;
/* Do not generate debug info for UNCONSTRAINED_ARRAY_TYPE that the
/* The general scheme is fairly simple:
For each builtin function/type to be declared, gnat_install_builtins calls
- internal facilities which eventually get to gnat_push_decl, which in turn
+ internal facilities which eventually get to gnat_pushdecl, which in turn
tracks the so declared builtin function decls in the 'builtin_decls' global
datastructure. When an Intrinsic subprogram declaration is processed, we
search this global datastructure to retrieve the associated BUILT_IN DECL