On Tue, 2014-09-23 at 14:17 +0200, Andreas Arnez wrote:
> > Also note that the logic wouldn't scale too well for yet more
> > qualifiers...
>
> Considering this, I've tried a different approach below. What do you
> think?
Having support in tree.c instead of doing it by hand in dwarf2out.c is
certainly nice.
> -- >8 --
> Subject: [PATCH] PR63300 'const volatile' sometimes stripped in debug info.
>
> When adding DW_TAG_restrict_type the handling of multiple modifiers
> was adjusted incorrectly. This patch fixes it with the help of a new
> tree function get_nearest_type_subqualifiers.
>
> gcc/ChangeLog
>
> * tree.c (check_base_type): New.
> (check_qualified_type): Exploit new helper function above.
> (get_nearest_type_subqualifiers): New.
> * tree.h (get_nearest_type_subqualifiers): New prototype.
> * dwarf2out.c (modified_type_die): Fix handling for qualifiers.
> Next qualifier to "peel off" is now determined with the help of
> get_nearest_type_subqualifiers.
> + if (cv_quals)
> + {
> + int q;
> + enum dwarf_tag t;
> +
> + q = get_nearest_type_subqualifiers (type, cv_quals, cv_qual_mask);
> + q = cv_quals & ~q;
> +
> + if (q & TYPE_QUAL_CONST)
> + {
> + q = TYPE_QUAL_CONST;
> + t = DW_TAG_const_type;
> + }
> + else if (q & TYPE_QUAL_VOLATILE)
> + {
> + q = TYPE_QUAL_VOLATILE;
> + t = DW_TAG_volatile_type;
> + }
> + else
> + {
> + q = TYPE_QUAL_RESTRICT;
> + t = DW_TAG_restrict_type;
> + }
>
> + mod_type_die = new_die (t, mod_scope, type);
> + sub_die = modified_type_die (type, cv_quals & ~q, context_die);
This certainly looks nicer than how I wrote it. It took me a while
(again) to realize why this works. We rely on the fact that earlier in
the function a match would have been found if there was already a fully
qualified type available. So here we know some subset will be found and
at least one qualifier we need will not be in the result returned by
get_nearest_type_subqualifiers. Maybe add a comment saying that to the
code?
Could you add the testcases I wrote for my variant of the fix to your
patch and make sure they PASS?
Thanks,
Mark