PATCH RFA: Support Plan 9 extensions in gcc
Ian Lance Taylor
iant@google.com
Thu Sep 30 11:54:00 GMT 2010
"Joseph S. Myers" <joseph@codesourcery.com> writes:
> On Sun, 26 Sep 2010, Ian Lance Taylor wrote:
>
>> Joseph Myers asked specifically about standardization; I very much doubt
>> the Plan 9 folks care one way or another about whether this
>> functionality is added to the standard. However, it seems to me
>> unlikely that any contradictory functionality would be added.
>
> It is also the case that we now know what form of anonymous structures and
> unions is in C1X and I implemented support for that in GCC.
Thanks for the review. You are correct that I didn't fully grasp the
fact that anonymous structures and unions are now implemented.
> However, one case of ambiguity that this patch does not detect appears to
> conflict with the standard semantics.
>
> typedef struct { int a; } s1;
> struct s2 { s1; int s1; };
> int f(struct s2 *p) { return p->s1; }
>
> In C1X, p->s1 is an unambiguous reference to the int field. With
> -fplan9-extensions, there is ambiguity; this is not detected as such, but
> instead you get an error:
>
> t1.c:3:23: error: incompatible types when returning type 's1' but 'int' was expected
>
> Logically this option should perhaps cause such a case to be detected with
> an error for duplicate fields (and so be documented as causing some code
> to be rejected that is otherwise accepted).
I have implemented this, and added a test case.
> The duplicate field errors for anonymous structures and unions post-date
> your previous patch. I don't actually see how the other cases of
> ambiguity that your patch tries to detect can arise without an error being
> given earlier for duplicate field names - they all involve multiple fields
> with the same anonymous structure or union type, which would mean all the
> fields within that type are duplicated.
I agree. I have removed the ambiguity detection, and the code now
relies on the duplicate field test.
Here is the updated patch. Bootstrapped and tested on
x86_64-unknown-linux-gnu. OK for mainline?
Ian
gcc/ChangeLog:
2010-09-29 Ian Lance Taylor <iant@google.com>
* c-typeck.c (lookup_field): If -fplan9-extensions, permit
referring to a field using a typedef name.
(find_anonymous_field_with_type): New static function.
(convert_to_anonymous_field): New static function.
(convert_for_assignment): If -fplan9-extensions, permit converting
pointer to struct to pointer to anonymous field.
* c-decl.c (grokfield): If -fplan9-extensions, permit anonymous
fields.
(is_duplicate_field): New static function.
(detect_field_duplicates_hash): If -fplan9-extensions, check for
typedef names duplicating field names.
(detect_field_duplicates): Likewise.
* doc/invoke.texi (Option Summary): Mention -fplan9-extensions.
(C Dialect Options): Document -fplan9-extensions.
* doc/extend.texi (Unnamed Fields): Document -fplan9-extensions.
gcc/c-family/ChangeLog:
2010-09-29 Ian Lance Taylor <iant@google.com>
* c.opt (-fplan9-extensions): New option.
gcc/testsuite/ChangeLog:
2010-09-29 Ian Lance Taylor <iant@google.com>
* c-typeck.c (lookup_field): If -fplan9-extensions, permit
referring to a field using a typedef name.
(find_anonymous_field_with_type): New static function.
(convert_to_anonymous_field): New static function.
(convert_for_assignment): If -fplan9-extensions, permit converting
pointer to struct to pointer to anonymous field.
* c-decl.c (grokfield): If -fplan9-extensions, permit anonymous
fields.
(is_duplicate_field): New static function.
(detect_field_duplicates_hash): If -fplan9-extensions, check for
typedef names duplicating field names.
(detect_field_duplicates): Likewise.
* doc/invoke.texi (Option Summary): Mention -fplan9-extensions.
(C Dialect Options): Document -fplan9-extensions.
* doc/extend.texi (Unnamed Fields): Document -fplan9-extensions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-diff
Size: 18740 bytes
Desc: plan9
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20100930/608e684a/attachment.bin>
More information about the Gcc-patches
mailing list