This is an archive of the discontinued LLVM Phabricator instance.

Begin implementing Plan 9 C extensions.
Needs ReviewPublic

Authored by pcc on May 20 2014, 1:59 PM.

Details

Reviewers
rsmith
Summary

This makes a start on implementing a number of extensions provided by the Plan
9 C compiler, from which Go's "cc" C compiler is derived. These extensions
are required for building some parts of the Go standard library.

This patch introduces the -fplan9-extensions flag and causes it to enable
an extension which allows typedefs to be declared multiple times.

Diff Detail

Event Timeline

pcc updated this revision to Diff 9640.May 20 2014, 1:59 PM
pcc retitled this revision from to Begin implementing Plan 9 C extensions..
pcc updated this object.
pcc edited the test plan for this revision. (Show Details)
pcc added a subscriber: Unknown Object (MLST).
thakis added a subscriber: thakis.May 20 2014, 2:21 PM

Is there a list of extensions you want to support?

Could the go standard library not use plan9 extensions, if it's interested
in being compiled with more than 1 compiler?

ruiu added a subscriber: ruiu.May 20 2014, 2:34 PM

Go will be rewritten in Go after Go 1.3 release which is planned on June 1.
I don't know the time frame, if Go 1.4 is coming soon, you don't need to
implement Plan 9 C extensions in Clang, do you?

This is probably a necessary step to targeting Plan 9 as well.

arthur.j.odwyer added inline comments.
lib/Sema/SemaDecl.cpp
1772

"as do C11 and Plan 9"

There are a few other extensions that should be supported. Plan9-style C also supports accessing anonymous structure and union members by type name iff they are declared using a typedef name. For example, p.Point in:

typedef struct Point
{
    int x, y;
} Point;

struct
{
    int type;
    Point;
} p;

void take(Point* point);

It also supports using the address of the parent struct without a cast anywhere that the address of the anonymous member is used, as in take(p). The compiler should automatically promote the type, adjust the address, and suppress the otherwise germane [-Wincompatible-pointer-types] warning.

I'm not sure whether these two extensions are leveraged in the Go 1.3 compiler, but they are frequently used in Plan 9 itself, and are necessary for compiling it.

If someone wants to pick this up and run with it, this patch is fine as a starting point (though will need to be rebased).

ormris added a subscriber: ormris.Jan 11 2019, 9:17 AM