gdb/ChangeLog 2015-04-18 Jan Kratochvil compile: Fix crash on cv-qualified self-reference. * compile/compile-c-types.c (convert_struct_or_union): Apply build_qualified_type. (convert_type_basic): Do not apply build_qualified_type for TYPE_CODE_STRUCT and TYPE_CODE_UNION. gdb/testsuite/ChangeLog 2015-04-18 Jan Kratochvil compile: Fix crash on cv-qualified self-reference. * gdb.compile/compile.c (struct struct_type): Add volatile for selffield. diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c index 2b521bc..420f61d 100644 --- a/gdb/compile/compile-c-types.c +++ b/gdb/compile/compile-c-types.c @@ -166,9 +166,13 @@ convert_struct_or_union (struct compile_c_instance *context, struct type *type) { int i; gcc_type result; + int quals; /* First we create the resulting type and enter it into our hash - table. This lets recursive types work. */ + table. This lets recursive types work. We have to create gcc_type + already with its qualifiers to prevent recursively calling + build_qualified_type for unfinished TYPE as build_qualified_type + creates a copy of the type, remaining unfinished forever. */ if (TYPE_CODE (type) == TYPE_CODE_STRUCT) result = C_CTX (context)->c_ops->build_record_type (C_CTX (context)); else @@ -176,6 +180,15 @@ convert_struct_or_union (struct compile_c_instance *context, struct type *type) gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION); result = C_CTX (context)->c_ops->build_union_type (C_CTX (context)); } + 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); 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); switch (TYPE_CODE (type)) diff --git a/gdb/testsuite/gdb.compile/compile.c b/gdb/testsuite/gdb.compile/compile.c index 3d5f20a..41ff087 100644 --- a/gdb/testsuite/gdb.compile/compile.c +++ b/gdb/testsuite/gdb.compile/compile.c @@ -42,7 +42,7 @@ struct struct_type { float floatfield; double doublefield; const union union_type *ptrfield; - struct struct_type *selffield; + volatile struct struct_type *selffield; int arrayfield[5]; _Complex double complexfield; _Bool boolfield;