* [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
* Re: [gcc libcc1] build_qualified_type for self-referencing/incomplete types
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
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2015-04-14 6:09 UTC (permalink / raw)
To: gcc; +Cc: Phil Muldoon, Tom Tromey, gdb
On Fri, 10 Apr 2015 14:31:45 +0200, Jan Kratochvil wrote:
> What is the recommended fix? I expect pointer to a declaration / opaque type
> which gets completed only when one references the 'p' field later?
It looks as it got fixed by:
-plugin_build_record_type (cc1_plugin::connection *self)
+plugin_build_record_type (cc1_plugin::connection *self, const char *name)
{
plugin_context *ctx = static_cast<plugin_context *> (self);
- return convert_out (ctx->preserve (make_node (RECORD_TYPE)));
+ tree node (make_node (RECORD_TYPE));
+ tree type_decl (build_decl (input_location, TYPE_DECL, get_identifier (name),
+ node));
+ TYPE_NAME (node) = type_decl;
+ TYPE_STUB_DECL (node) = type_decl;
+ C_TYPE_BEING_DEFINED (node) = 1;
+ return convert_out (ctx->preserve (node));
Jan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gcc libcc1] build_qualified_type for self-referencing/incomplete types
2015-04-14 6:09 ` Jan Kratochvil
@ 2015-04-17 15:22 ` Jan Kratochvil
2015-04-18 10:20 ` Jan Kratochvil
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2015-04-17 15:22 UTC (permalink / raw)
To: gcc; +Cc: Phil Muldoon, Tom Tromey, gdb
On Tue, 14 Apr 2015 08:09:05 +0200, Jan Kratochvil wrote:
> On Fri, 10 Apr 2015 14:31:45 +0200, Jan Kratochvil wrote:
> > What is the recommended fix? I expect pointer to a declaration / opaque type
> > which gets completed only when one references the 'p' field later?
>
> It looks as it got fixed by:
It did not.
As I was told the mail was unclear - to simplify the question:
How to get 'volatile struct sv' GCC 'tree' type for:
volatile struct sv { volatile struct sv *p; };
Thanks,
Jan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gcc libcc1] build_qualified_type for self-referencing/incomplete types
2015-04-17 15:22 ` Jan Kratochvil
@ 2015-04-18 10:20 ` Jan Kratochvil
2015-04-23 22:06 ` Jeff Law
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2015-04-18 10:20 UTC (permalink / raw)
To: gcc; +Cc: Phil Muldoon, Tom Tromey, gdb
On Fri, 17 Apr 2015 17:22:13 +0200, Jan Kratochvil wrote:
> How to get 'volatile struct sv' GCC 'tree' type for:
> volatile struct sv { volatile struct sv *p; };
I have found out how it can work, even with no change on the GCC side:
Instead of current:
plugin_build_record_type:
record_type = make_node (RECORD_TYPE)
plugin_build_add_field:
add fields to record_type... But there is no qualified_record_type here!
plugin_finish_record_or_union:
TYPE_SIZE (record_type) etc. ... to finish the type
plugin_build_qualified_type:
qualified_record_type = build_qualified_type (record_type, ...)
one can do instead:
plugin_build_record_type:
record_type = make_node (RECORD_TYPE)
plugin_build_qualified_type:
qualified_record_type = build_qualified_type (record_type, ...)
plugin_build_add_field:
add fields to qualified_record_type
plugin_finish_record_or_union:
TYPE_SIZE (qualified_record_type) etc. ... to finish the type
And one forgets about the unfinished record_type.
For a different cv-quals of the same record type one builds a new cv-qualified
record from scratch.
Jan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gcc libcc1] build_qualified_type for self-referencing/incomplete types
2015-04-18 10:20 ` Jan Kratochvil
@ 2015-04-23 22:06 ` Jeff Law
2015-04-24 6:27 ` Jan Kratochvil
0 siblings, 1 reply; 6+ messages in thread
From: Jeff Law @ 2015-04-23 22:06 UTC (permalink / raw)
To: Jan Kratochvil, gcc; +Cc: Phil Muldoon, Tom Tromey, gdb
On 04/18/2015 04:19 AM, Jan Kratochvil wrote:
> On Fri, 17 Apr 2015 17:22:13 +0200, Jan Kratochvil wrote:
>> How to get 'volatile struct sv' GCC 'tree' type for:
>> volatile struct sv { volatile struct sv *p; };
>
> I have found out how it can work, even with no change on the GCC side:
>
> Instead of current:
> plugin_build_record_type:
> record_type = make_node (RECORD_TYPE)
> plugin_build_add_field:
> add fields to record_type... But there is no qualified_record_type here!
> plugin_finish_record_or_union:
> TYPE_SIZE (record_type) etc. ... to finish the type
> plugin_build_qualified_type:
> qualified_record_type = build_qualified_type (record_type, ...)
> one can do instead:
> plugin_build_record_type:
> record_type = make_node (RECORD_TYPE)
> plugin_build_qualified_type:
> qualified_record_type = build_qualified_type (record_type, ...)
> plugin_build_add_field:
> add fields to qualified_record_type
> plugin_finish_record_or_union:
> TYPE_SIZE (qualified_record_type) etc. ... to finish the type
> And one forgets about the unfinished record_type.
>
> For a different cv-quals of the same record type one builds a new cv-qualified
> record from scratch.
I'm a bit surprised the former didn't work, but if the latter is working
consistently, then I'd stick with it.
jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [gcc libcc1] build_qualified_type for self-referencing/incomplete types
2015-04-23 22:06 ` Jeff Law
@ 2015-04-24 6:27 ` Jan Kratochvil
0 siblings, 0 replies; 6+ messages in thread
From: Jan Kratochvil @ 2015-04-24 6:27 UTC (permalink / raw)
To: Jeff Law; +Cc: gcc, Phil Muldoon, Tom Tromey, gdb
On Fri, 24 Apr 2015 00:06:46 +0200, Jeff Law wrote:
> On 04/18/2015 04:19 AM, Jan Kratochvil wrote:
> > Instead of current:
> > plugin_build_record_type:
> > record_type = make_node (RECORD_TYPE)
> > plugin_build_add_field:
> > add fields to record_type... But there is no qualified_record_type here!
> > plugin_finish_record_or_union:
> > TYPE_SIZE (record_type) etc. ... to finish the type
> > plugin_build_qualified_type:
> > qualified_record_type = build_qualified_type (record_type, ...)
[...]
> I'm a bit surprised the former didn't work,
build_qualified_type() will make a copy of the type being created. While the
original type gets finished later (added more fields and its final TYPE_SIZE)
the copy remains unfinished forever and GCC later crashes trying to access the
unfinished copy.
> but if the latter is working consistently, then I'd stick with it.
Yes, it is solved now.
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).