Commit 5101b304 by Mark Mitchell Committed by Mark Mitchell

dwarf2out.c (modified_type_die): Don't create new types here.

	* dwarf2out.c (modified_type_die): Don't create new types here.
	* tree.h (get_qualified_type): New function.
	(build_qualified_type): Adjust comment.
	* tree.c (get_qualified_type): New function.
	(build_qualified_type): Use it.

From-SVN: r41276
parent e98d0cea
2001-04-11 Mark Mitchell <mark@codesourcery.com>
* dwarf2out.c (modified_type_die): Don't create new types here.
* tree.h (get_qualified_type): New function.
(build_qualified_type): Adjust comment.
* tree.c (get_qualified_type): New function.
(build_qualified_type): Use it.
2001-04-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2001-04-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* cpp.texi (-Wtraditional): Update description. * cpp.texi (-Wtraditional): Update description.
......
...@@ -6812,22 +6812,35 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die) ...@@ -6812,22 +6812,35 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
if (code != ERROR_MARK) if (code != ERROR_MARK)
{ {
type = build_type_variant (type, is_const_type, is_volatile_type); tree qualified_type;
mod_type_die = lookup_type_die (type); /* See if we already have the appropriately qualified variant of
if (mod_type_die) this type. */
return mod_type_die; qualified_type
= get_qualified_type (type,
((is_const_type ? TYPE_QUAL_CONST : 0)
| (is_volatile_type
? TYPE_QUAL_VOLATILE : 0)));
/* If we do, then we can just use its DIE, if it exists. */
if (qualified_type)
{
mod_type_die = lookup_type_die (qualified_type);
if (mod_type_die)
return mod_type_die;
}
/* Handle C typedef types. */ /* Handle C typedef types. */
if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL if (qualified_type && TYPE_NAME (qualified_type)
&& DECL_ORIGINAL_TYPE (TYPE_NAME (type))) && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
{ {
tree dtype = TREE_TYPE (TYPE_NAME (type)); tree type_name = TYPE_NAME (qualified_type);
if (type == dtype) tree dtype = TREE_TYPE (type_name);
if (qualified_type == dtype)
{ {
/* For a named type, use the typedef. */ /* For a named type, use the typedef. */
gen_type_die (type, context_die); gen_type_die (qualified_type, context_die);
mod_type_die = lookup_type_die (type); mod_type_die = lookup_type_die (qualified_type);
} }
else if (is_const_type < TYPE_READONLY (dtype) else if (is_const_type < TYPE_READONLY (dtype)
...@@ -6835,7 +6848,7 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die) ...@@ -6835,7 +6848,7 @@ modified_type_die (type, is_const_type, is_volatile_type, context_die)
/* cv-unqualified version of named type. Just use the unnamed /* cv-unqualified version of named type. Just use the unnamed
type to which it refers. */ type to which it refers. */
mod_type_die mod_type_die
= modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
is_const_type, is_volatile_type, is_const_type, is_volatile_type,
context_die); context_die);
/* Else cv-qualified version of named type; fall through. */ /* Else cv-qualified version of named type; fall through. */
......
// Build don't link:
// Special g++ Options: -g
struct X {
const int x[4];
};
struct A {
A();
A(const A&);
};
struct B {
A a;
int b[4];
};
struct C {
A a;
C() { B b=B(); };
};
...@@ -2993,31 +2993,47 @@ set_type_quals (type, type_quals) ...@@ -2993,31 +2993,47 @@ set_type_quals (type, type_quals)
TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0; TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
} }
/* Given a type node TYPE and a TYPE_QUALIFIER_SET, return a type for /* Return a version of the TYPE, qualified as indicated by the
the same kind of data as TYPE describes. Variants point to the TYPE_QUALS, if one exists. If no qualified version exists yet,
"main variant" (which has no qualifiers set) via TYPE_MAIN_VARIANT, return NULL_TREE. */
and it points to a chain of other variants so that duplicate
variants are never made. Only main variants should ever appear as
types of expressions. */
tree tree
build_qualified_type (type, type_quals) get_qualified_type (type, type_quals)
tree type; tree type;
int type_quals; int type_quals;
{ {
register tree t; tree t;
/* Search the chain of variants to see if there is already one there just /* Search the chain of variants to see if there is already one there just
like the one we need to have. If so, use that existing one. We must like the one we need to have. If so, use that existing one. We must
preserve the TYPE_NAME, since there is code that depends on this. */ preserve the TYPE_NAME, since there is code that depends on this. */
for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type)) if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type))
return t; return t;
/* We need a new one. */ return NULL_TREE;
t = build_type_copy (type); }
set_type_quals (t, type_quals);
/* Like get_qualified_type, but creates the type if it does not
exist. This function never returns NULL_TREE. */
tree
build_qualified_type (type, type_quals)
tree type;
int type_quals;
{
tree t;
/* See if we already have the appropriate qualified variant. */
t = get_qualified_type (type, type_quals);
/* If not, build it. */
if (!t)
{
t = build_type_copy (type);
set_type_quals (t, type_quals);
}
return t; return t;
} }
......
...@@ -2060,12 +2060,14 @@ extern tree lookup_attribute PARAMS ((const char *, tree)); ...@@ -2060,12 +2060,14 @@ extern tree lookup_attribute PARAMS ((const char *, tree));
extern tree merge_attributes PARAMS ((tree, tree)); extern tree merge_attributes PARAMS ((tree, tree));
/* Given a type node TYPE and a TYPE_QUALIFIER_SET, return a type for /* Return a version of the TYPE, qualified as indicated by the
the same kind of data as TYPE describes. Variants point to the TYPE_QUALS, if one exists. If no qualified version exists yet,
"main variant" (which has no qualifiers set) via TYPE_MAIN_VARIANT, return NULL_TREE. */
and it points to a chain of other variants so that duplicate
variants are never made. Only main variants should ever appear as extern tree get_qualified_type PARAMS ((tree, int));
types of expressions. */
/* Like get_qualified_type, but creates the type if it does not
exist. This function never returns NULL_TREE. */
extern tree build_qualified_type PARAMS ((tree, int)); extern tree build_qualified_type PARAMS ((tree, int));
......
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