[gcc libcc1] build_qualified_type for self-referencing/incomplete types

Jan Kratochvil <[email protected]>
Newsgroups gmane.comp.gcc.devel,gmane.comp.gdb.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.