[PATCH] Begin implementing Plan 9 C extensions.

Alp Toker alp at nuanti.com
Tue May 20 14:25:21 PDT 2014


Hi

Is this http://plan9.bell-labs.com/sys/doc/compiler.html ?

Looks like there's a fair bit of ground to cover to support this in clang.

Some extensions like unnamed substructures could borrow from 
-fms-extensions but others like structure displays and initialization 
indexes would appear to require new parse rules and semantic analysis.

How many active projects out there are actually using this language 
mode? There doesn't appear to be much recent (< 24 years old) material 
on the language online.

Alp.



On 20/05/2014 23:59, Peter Collingbourne wrote:
> 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.
>
> http://reviews.llvm.org/D3853
>
> Files:
>    include/clang/Basic/LangOptions.def
>    include/clang/Driver/Options.td
>    lib/Driver/Tools.cpp
>    lib/Frontend/CompilerInvocation.cpp
>    lib/Sema/SemaDecl.cpp
>    test/Sema/c11-typedef-redef.c
>
> Index: include/clang/Basic/LangOptions.def
> ===================================================================
> --- include/clang/Basic/LangOptions.def
> +++ include/clang/Basic/LangOptions.def
> @@ -47,6 +47,7 @@
>   LANGOPT(MicrosoftExt      , 1, 0, "Microsoft C++ extensions")
>   LANGOPT(AsmBlocks         , 1, 0, "Microsoft inline asm blocks")
>   LANGOPT(Borland           , 1, 0, "Borland extensions")
> +LANGOPT(Plan9Ext          , 1, 0, "Plan 9 extensions")
>   LANGOPT(CPlusPlus         , 1, 0, "C++")
>   LANGOPT(CPlusPlus11       , 1, 0, "C++11")
>   LANGOPT(CPlusPlus1y       , 1, 0, "C++1y")
> Index: include/clang/Driver/Options.td
> ===================================================================
> --- include/clang/Driver/Options.td
> +++ include/clang/Driver/Options.td
> @@ -775,6 +775,8 @@
>   def fno_pic : Flag<["-"], "fno-pic">, Group<f_Group>;
>   def fpie : Flag<["-"], "fpie">, Group<f_Group>;
>   def fno_pie : Flag<["-"], "fno-pie">, Group<f_Group>;
> +def fplan9_extensions : Flag<["-"], "fplan9-extensions">, Group<f_Group>, Flags<[CC1Option]>;
> +def fno_plan9_extensions : Flag<["-"], "fno-plan9-extensions">, Group<f_Group>;
>   def fprofile_arcs : Flag<["-"], "fprofile-arcs">, Group<f_Group>;
>   def fprofile_generate : Flag<["-"], "fprofile-generate">, Group<f_Group>;
>   def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>;
> Index: lib/Driver/Tools.cpp
> ===================================================================
> --- lib/Driver/Tools.cpp
> +++ lib/Driver/Tools.cpp
> @@ -3678,6 +3678,11 @@
>                      options::OPT_fno_borland_extensions, false))
>       CmdArgs.push_back("-fborland-extensions");
>   
> +  // -fno-plan9-extensions is default.
> +  if (Args.hasFlag(options::OPT_fplan9_extensions,
> +                   options::OPT_fno_plan9_extensions, false))
> +    CmdArgs.push_back("-fplan9-extensions");
> +
>     // -fno-delayed-template-parsing is default, except for Windows where MSVC STL
>     // needs it.
>     if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
> Index: lib/Frontend/CompilerInvocation.cpp
> ===================================================================
> --- lib/Frontend/CompilerInvocation.cpp
> +++ lib/Frontend/CompilerInvocation.cpp
> @@ -1351,6 +1351,7 @@
>     Opts.MSCVersion = getLastArgIntValue(Args, OPT_fmsc_version, 0, Diags);
>     Opts.VtorDispMode = getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags);
>     Opts.Borland = Args.hasArg(OPT_fborland_extensions);
> +  Opts.Plan9Ext = Args.hasArg(OPT_fplan9_extensions);
>     Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
>     Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings,
>                                      Opts.ConstStrings);
> Index: lib/Sema/SemaDecl.cpp
> ===================================================================
> --- lib/Sema/SemaDecl.cpp
> +++ lib/Sema/SemaDecl.cpp
> @@ -1769,8 +1769,8 @@
>       return New->setInvalidDecl();
>     }
>   
> -  // Modules always permit redefinition of typedefs, as does C11.
> -  if (getLangOpts().Modules || getLangOpts().C11)
> +  // Modules always permit redefinition of typedefs, as does C11 and Plan 9.
> +  if (getLangOpts().Modules || getLangOpts().C11 || getLangOpts().Plan9Ext)
>       return;
>     
>     // If we have a redefinition of a typedef in C, emit a warning.  This warning
> Index: test/Sema/c11-typedef-redef.c
> ===================================================================
> --- test/Sema/c11-typedef-redef.c
> +++ test/Sema/c11-typedef-redef.c
> @@ -1,4 +1,5 @@
>   // RUN: %clang_cc1 -std=c11 %s -verify
> +// RUN: %clang_cc1 -fplan9-extensions %s -verify
>   
>   typedef int type;
>   typedef type type;
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-- 
http://www.nuanti.com
the browser experts




More information about the cfe-commits mailing list