This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patchv2] compile: Fix crash on cv-qualified self-reference
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: gdb-patches at sourceware dot org, Phil Muldoon <pmuldoon at redhat dot com>
- Date: Wed, 01 Jul 2015 12:21:32 +0100
- Subject: Re: [patchv2] compile: Fix crash on cv-qualified self-reference
- Authentication-results: sourceware.org; auth=none
- References: <20150418172843 dot GA17777 at host1 dot jankratochvil dot net> <20150516132555 dot GB17266 at host1 dot jankratochvil dot net>
Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> + quals = 0;
> + if (TYPE_CONST (type))
> + quals |= GCC_QUALIFIER_CONST;
> + if (TYPE_VOLATILE (type))
> + quals |= GCC_QUALIFIER_VOLATILE;
> + if (TYPE_RESTRICT (type))
> + quals |= GCC_QUALIFIER_RESTRICT;
> + result = C_CTX (context)->c_ops->build_qualified_type (C_CTX (context),
> + result, quals);
> insert_type (context, type, result);
Can we use convert_qualified instead? I find code we added here is
quite similar to convert_qualified.
>
> for (i = 0; i < TYPE_NFIELDS (type); ++i)
> @@ -329,10 +342,13 @@ static gcc_type
> convert_type_basic (struct compile_c_instance *context, struct type *type)
> {
> /* If we are converting a qualified type, first convert the
> - unqualified type and then apply the qualifiers. */
> + unqualified type and then apply the qualifiers, except for the
> + types handling qualifiers on their own. */
> if ((TYPE_INSTANCE_FLAGS (type) & (TYPE_INSTANCE_FLAG_CONST
> | TYPE_INSTANCE_FLAG_VOLATILE
> - | TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
> + | TYPE_INSTANCE_FLAG_RESTRICT)) != 0
> + && (TYPE_CODE (type) != TYPE_CODE_STRUCT
> + && TYPE_CODE (type) != TYPE_CODE_UNION))
> return convert_qualified (context, type);
It looks right to me, however, isn't cleaner to do in this way?
/* Comments on why we do this first */
if (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION)
return convert_struct_or_union (context, type);
/* If we are converting a qualified type, first convert the
unqualified type and then apply the qualifiers. */
if ((TYPE_INSTANCE_FLAGS (type) & (TYPE_INSTANCE_FLAG_CONST
| TYPE_INSTANCE_FLAG_VOLATILE
| TYPE_INSTANCE_FLAG_RESTRICT)) != 0)
return convert_qualified (context, type);
switch (TYPE_CODE (type))
{
/* Don't need to handle TYPE_CODE_STRUCT and TYPE_CODE_UNION
here. */
}
Otherwise, the patch looks good to me.
--
Yao (éå)