This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
[gcc libcc1] build_qualified_type for self-referencing/incomplete types
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gcc at gcc dot gnu dot org
- Cc: Phil Muldoon <pmuldoon at redhat dot com>, Tom Tromey <tom at tromey dot com>, gdb at sourceware dot org
- Date: Fri, 10 Apr 2015 14:31:45 +0200
- Subject: [gcc libcc1] build_qualified_type for self-referencing/incomplete types
- Authentication-results: sourceware.org; auth=none
Hi,
[compile] cv-qualified self-references crash
https://sourceware.org/bugzilla/show_bug.cgi?id=18202
------------------------------------------------------------------------------
cat >1.c <<EOH
// b tree.c:build_qualified_type
// p TYPE_SIZE (type)
volatile struct sv { volatile struct sv *p; } sv; // CRASH: compile code sv.p
= &sv;
volatile struct s { int i; } s, *sp; // OK: compile code sp = &s;
int main(void) { return 0; }
EOH
gcc -o 1 1.c -Wall -g; gdb ./1 -ex start -ex 'compile code sv.p = &sv'
------------------------------------------------------------------------------
gdb command line:1:1: internal compiler error: Segmentation fault
0xd901f4 crash_signal
../../gccgitatsign/gcc/toplev.c:383
0x714941 c_incomplete_type_error(tree_node const*, tree_node const*)
../../gccgitatsign/gcc/c/c-typeck.c:282
0x71d4ff build_component_ref(unsigned int, tree_node*, tree_node*)
../../gccgitatsign/gcc/c/c-typeck.c:2304
[...]
------------------------------------------------------------------------------
The problem is GDB calls build_qualified_type() for that 'volatile' when
constructing the 'p' field while 'struct sv' is still incomplete that time.
That is at build_qualified_type() there is COMPLETE_TYPE_P(type)==false.
But build_qualified_type() create a copy of (not reference to) the type so
after 'struct sv' gets finished its 'p' still points to an incomplete type.
What is the recommended fix? I expect pointer to a declaration / opaque type
which gets completed only when one references the 'p' field later?
GDB currently does not fill in TYPE_NAME as it references all the types by
their addresses. So I guess GDB needs to start filling in TYPE_NAME at least
for RECORD_TYPEs and probably UNION_TYPEs.
Thanks,
Jan