public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gcc@gcc.gnu.org
Cc: Phil Muldoon <pmuldoon@redhat.com>, Tom Tromey <tom@tromey.com>,
	       gdb@sourceware.org
Subject: [gcc libcc1] build_qualified_type for self-referencing/incomplete types
Date: Fri, 10 Apr 2015 12:31:00 -0000	[thread overview]
Message-ID: <20150410123145.GA18073@host1.jankratochvil.net> (raw)

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

             reply	other threads:[~2015-04-10 12:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10 12:31 Jan Kratochvil [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150410123145.GA18073@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdb@sourceware.org \
    --cc=pmuldoon@redhat.com \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).