http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45997
--- Comment #4 from Dodji Seketeli <dodji at gcc dot gnu.org> 2010-11-08 22:39:09 UTC --- At some point modified_type_die is called for volatile_const_my_int with is_volatile and is_const_type set to 0, meaning we want to emit the DIE of the cv-unqualified version of volatile_const_my_int i.e, my_int. The problem is that the line /* See if we already have the appropriately qualified variant of this type. */ qualified_type = get_qualified_type (type, ((is_const_type ? TYPE_QUAL_CONST : 0) | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0))); fails to give us the the my_int (cv-unqualified version of volatile_const_my_int) we want and returns NULL instead. That's because get_qualified_type doesn't look through typedefs as it must preserve TYPE_NAMEs (see the comment in get_qualified_type). From this point, I think we are likely to loose. So, maybe if we try harder to come up with the cv-unqualified version of the input type, things will get better? This patch that (only lightly tested seems) to fix the problem too. What do you think? diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 9bb569b..f639e24 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -12715,6 +12715,19 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type, ((is_const_type ? TYPE_QUAL_CONST : 0) | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0))); + /* If TYPE is a typedef and we want its cv-unqualified version, + get_qualified_type just returns NULL because it doesn't look + through typedefs; In that case, let's use the underlying type of + the typedef. */ + if (qualified_type == NULL + && typedef_variant_p (type) + && (is_const_type < TYPE_READONLY (type) + || is_volatile_type < TYPE_VOLATILE (type))) + qualified_type = + get_qualified_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), + ((is_const_type ? TYPE_QUAL_CONST : 0) + | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0))); + if (qualified_type == sizetype && TYPE_NAME (qualified_type) && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)