This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH RFA: Support Plan 9 extensions in gcc


On Thu, Apr 9, 2009 at 9:35 PM, Ian Lance Taylor <iant@google.com> wrote:
> gcc currently supports an option -fms-extensions which permits some uses
> of unnamed fields in structs and unions. ?The Plan 9 C compiler has two
> extensions which are not included in -fms-extensions.
>
> The first extension is if a structure has an anonymous field, a pointer
> to that structure can be automatically converted to apointer to the
> anonymous field in an assignment or a function call. ?For example:
>
> struct s1 { int a; };
> struct s2 { int b; struct s1; };
> extern void f1 (struct s1 *);
> void f2 (struct s2 *p) { f1 (p); }
>
> Here struct s2 has an anonymous field of type struct s1. ?When calling
> f1 from f2, the pointer to s2 is converted into a pointer to s1. ?Note
> that the anonymous field is not the first field in s2, so this actually
> adjusts the pointer in order to make the call.
>
> The second extension is that if a pointer has an anonymous field, and
> the type of the anonymous field is a typedef for a struct or a union,
> then code can refer to the entire anonymous field using the typedef
> name. ?For example, this is valid:
>
> typedef struct { int a; } s3;
> struct s4 { s3; };
> s3 f1 (struct s4 *p) { return p->s3; }
>
> Note the use of the typedef name s3 as the name of a field in s4.
>
> In order to use gcc to compile code written for the Plan 9 compiler, gcc
> should support these extensions. ?Therefore, I propose the following
> patch. ?This has been bootstrapped and tested on i686-pc-linux-gnu.
>
> OK for mainline?

So - how is this useful and not only a maintainance burden?  Is there
a sufficiently large amount of free software that relies on this Plan 9 C
extension?

Thanks,
Richard.

> If committed, I will prepare an entry for the gcc 4.5 changes.html page.
>
> Ian
>
>
> gcc/ChangeLog:
>
> 2009-04-09 ?Ian Lance Taylor ?<iant@google.com>
>
> ? ? ? ?* c.opt (fplan9-extensions): New option.
> ? ? ? ?* c-typeck.c (lookup_field): If flag_plan9_extensions, permit
> ? ? ? ?using a typedef name for an anonymous field.
> ? ? ? ?(find_anonymous_field_with_type): New static function.
> ? ? ? ?(convert_to_anonymous_field): New static function.
> ? ? ? ?(convert_for_assignment): If flag_plan9_extensions, permit
> ? ? ? ?converting a pointer to a struct to a pointer to an anonymous
> ? ? ? ?field.
> ? ? ? ?* c-decl.c (grokfield): Handle flag_plan9_extensions like
> ? ? ? ?flag_ms_extensions.
> ? ? ? ?* doc/invoke.texi (Option Summary): Mention -fplan9-extensions.
> ? ? ? ?(C Dialect Options): Document -fplan9-extensions.
> ? ? ? ?* doc/extend.texi (Unnamed Fields): Document Plan 9 extensions.
>
> gcc/testsuite/ChangeLog:
>
> 2009-04-09 ?Ian Lance Taylor ?<iant@google.com>
>
> ? ? ? ?* gcc.dg/anon-struct-9.c: New test.
> ? ? ? ?* gcc.dg/anon-struct-10.c: New test.
>
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]