This patch enables the addition of extensions supported by the Plan 9 C compilers by adding the -fplan9-extensions flag.
This flag currently enables 1 extension: allowing typedefs to be declared multiple times like in C11. Once merged, I have plans to implement the following Plan 9 C compiler behavior, as covered below.
Plan 9 C compilers can be summarized as a C89 compiler with the following non-standard extensions enabled:
- Embedded structures, like Microsoft C (already implemented in Clang with -fms-extensions)
- Automatic embedded structure type decay
- Embedded structure type name accesses
As well as the following standardized C extensions enabled:
- C99 compound literals
- C99 designated initializers for arrays and structures
- C11 redeclaration of typedefs
- C11 anonymous structures and unions
- C2x omitting the parameter name in a function definition
A description of these extensions can be found in the How to Use the Plan 9 C Compiler paper by Rob Pike: https://9p.io/sys/doc/comp.html. However, there are no plans to implement the "extern register" feature, which is used in the kernel.
The motivation for this patch, and the patches that follow, are to enable the compilation of the Plan 9 kernel C source and Plan 9 userspace applications with Clang for the purpose of increased code optimizations and sanitizer instrumentation. In this respect, GCC support is inadequate, as it does not support the member resolution algorithm used in the Plan 9 C compilers to reconcile overlapping declaration names in a record.
This patch is largely based off of the following obsolete patch by @pcc: https://reviews.llvm.org/D3853.