public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* [gcc libcc1] build_qualified_type for self-referencing/incomplete types
@ 2015-04-10 12:31 Jan Kratochvil
  2015-04-14  6:09 ` Jan Kratochvil
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2015-04-10 12:31 UTC (permalink / raw)
  To: gcc; +Cc: Phil Muldoon, Tom Tromey, gdb

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-04-24  6:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-10 12:31 [gcc libcc1] build_qualified_type for self-referencing/incomplete types Jan Kratochvil
2015-04-14  6:09 ` Jan Kratochvil
2015-04-17 15:22   ` Jan Kratochvil
2015-04-18 10:20     ` Jan Kratochvil
2015-04-23 22:06       ` Jeff Law
2015-04-24  6:27         ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).