From: Richard Biener <richard.guenther@gmail.com>
To: gcc-patches@gcc.gnu.org,Joseph Myers <joseph@codesourcery.com>
Subject: Re: Add -std=c17, -std=gnu17
Date: Sat, 28 Oct 2017 21:57:00 -0000 [thread overview]
Message-ID: <F876A3D9-47A3-4A34-9A3D-D2DB45687CBB@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1710272155270.16427@digraph.polyomino.org.uk>
On October 27, 2017 11:56:47 PM GMT+02:00, Joseph Myers <joseph@codesourcery.com> wrote:
>C17, a bug-fix version of the C11 standard with DR resolutions
>integrated, will soon go to ballot. This patch adds corresponding
>options -std=c17, -std=gnu17 (new default version, replacing
>-std=gnu11 as the default), -std=iso9899:2017. As a bug-fix version
>of the standard, there is no need for flag_isoc17 or any options for
>compatibility warnings; however, there is a new __STDC_VERSION__
>value, so new cpplib languages CLK_GNUC17 and CLK_STDC17 are added to
>support using that new value with the new options. (If the standard
>ends up being published in 2018 and being known as C18, option aliases
>can be added. Note however that -std=iso9899:199409 corresponds to a
>__STDC_VERSION__ value rather than a publication date.)
>
>(There are a couple of DR resolutions needing implementing in GCC, but
>that's independent of the new options.)
>
>(I'd propose to add -std=c2x / -std=gnu2x / -Wc11-c2x-compat for the
>next major C standard revision once there are actually C2x drafts
>being issued with new features included.)
>
>Bootstrapped with no regressions for x86_64-pc-linux-gnu. Are the
>non-front-end changes for the "GNU C17" language name OK?
Yes.
Richard.
>gcc:
>2017-10-27 Joseph Myers <joseph@codesourcery.com>
>
> * doc/invoke.texi (C Dialect Options): Document -std=c17,
> -std=iso9899:2017 and -std=gnu17.
> * doc/standards.texi (C Language): Document C17 support.
> * doc/cpp.texi (Overview): Mention -std=c17.
> (Standard Predefined Macros): Document C11 and C17 values of
> __STDC_VERSION__. Do not refer to C99 support as incomplete.
> * doc/extend.texi (Inline): Do not list individual options for
> standards newer than C99.
> * dwarf2out.c (highest_c_language, gen_compile_unit_die): Handle
> "GNU C17".
> * config/rl78/rl78.c (rl78_option_override): Handle "GNU C17"
> language name.
>
>gcc/c-family:
>2017-10-27 Joseph Myers <joseph@codesourcery.com>
>
> * c.opt (std=c17, std=gnu17, std=iso9899:2017): New options.
> * c-opts.c (set_std_c17): New function.
> (c_common_init_options): Use gnu17 as default C version.
> (c_common_handle_option): Handle -std=c17 and -std=gnu17.
>
>gcc/testsuite:
>2017-10-27 Joseph Myers <joseph@codesourcery.com>
>
> * gcc.dg/c17-version-1.c, gcc.dg/c17-version-2.c: New tests.
>
>libcpp:
>2017-10-27 Joseph Myers <joseph@codesourcery.com>
>
> * include/cpplib.h (enum c_lang): Add CLK_GNUC17 and CLK_STDC17.
> * init.c (lang_defaults): Add GNUC17 and STDC17 data.
> (cpp_init_builtins): Handle C17 value of __STDC_VERSION__.
>
>Index: gcc/c-family/c-opts.c
>===================================================================
>--- gcc/c-family/c-opts.c (revision 254145)
>+++ gcc/c-family/c-opts.c (working copy)
>@@ -115,6 +115,7 @@ static void set_std_cxx2a (int);
> static void set_std_c89 (int, int);
> static void set_std_c99 (int);
> static void set_std_c11 (int);
>+static void set_std_c17 (int);
> static void check_deps_environment_vars (void);
> static void handle_deferred_opts (void);
> static void sanitize_cpp_opts (void);
>@@ -236,8 +237,8 @@ c_common_init_options (unsigned int decoded_option
>
> if (c_language == clk_c)
> {
>- /* The default for C is gnu11. */
>- set_std_c11 (false /* ISO */);
>+ /* The default for C is gnu17. */
>+ set_std_c17 (false /* ISO */);
>
> /* If preprocessing assembly language, accept any of the C-family
> front end options since the driver may pass them through. */
>@@ -675,6 +676,16 @@ c_common_handle_option (size_t scode, const char *
> set_std_c11 (false /* ISO */);
> break;
>
>+ case OPT_std_c17:
>+ if (!preprocessing_asm_p)
>+ set_std_c17 (true /* ISO */);
>+ break;
>+
>+ case OPT_std_gnu17:
>+ if (!preprocessing_asm_p)
>+ set_std_c17 (false /* ISO */);
>+ break;
>+
> case OPT_trigraphs:
> cpp_opts->trigraphs = 1;
> break;
>@@ -1559,6 +1570,21 @@ set_std_c11 (int iso)
> lang_hooks.name = "GNU C11";
> }
>
>+/* Set the C 17 standard (without GNU extensions if ISO). */
>+static void
>+set_std_c17 (int iso)
>+{
>+ cpp_set_lang (parse_in, iso ? CLK_STDC17: CLK_GNUC17);
>+ flag_no_asm = iso;
>+ flag_no_nonansi_builtin = iso;
>+ flag_iso = iso;
>+ flag_isoc11 = 1;
>+ flag_isoc99 = 1;
>+ flag_isoc94 = 1;
>+ lang_hooks.name = "GNU C17";
>+}
>+
>+
> /* Set the C++ 98 standard (without GNU extensions if ISO). */
> static void
> set_std_cxx98 (int iso)
>Index: gcc/c-family/c.opt
>===================================================================
>--- gcc/c-family/c.opt (revision 254145)
>+++ gcc/c-family/c.opt (working copy)
>@@ -1944,6 +1944,10 @@ std=c1x
> C ObjC Alias(std=c11)
> Deprecated in favor of -std=c11.
>
>+std=c17
>+C ObjC
>+Conform to the ISO 2017 C standard.
>+
> std=c89
> C ObjC Alias(std=c90)
> Conform to the ISO 1990 C standard.
>@@ -2006,6 +2010,10 @@ std=gnu1x
> C ObjC Alias(std=gnu11)
> Deprecated in favor of -std=gnu11.
>
>+std=gnu17
>+C ObjC
>+Conform to the ISO 2017 C standard with GNU extensions.
>+
> std=gnu89
> C ObjC Alias(std=gnu90)
> Conform to the ISO 1990 C standard with GNU extensions.
>@@ -2042,6 +2050,10 @@ std=iso9899:2011
> C ObjC Alias(std=c11)
> Conform to the ISO 2011 C standard.
>
>+std=iso9899:2017
>+C ObjC Alias(std=c17)
>+Conform to the ISO 2017 C standard.
>+
> traditional
> Driver
>
>Index: gcc/config/rl78/rl78.c
>===================================================================
>--- gcc/config/rl78/rl78.c (revision 254145)
>+++ gcc/config/rl78/rl78.c (working copy)
>@@ -360,6 +360,7 @@ rl78_option_override (void)
> if (TARGET_ES0
> && strcmp (lang_hooks.name, "GNU C")
> && strcmp (lang_hooks.name, "GNU C11")
>+ && strcmp (lang_hooks.name, "GNU C17")
> && strcmp (lang_hooks.name, "GNU C89")
> && strcmp (lang_hooks.name, "GNU C99")
>/* Compiling with -flto results in a language of GNU GIMPLE being
>used... */
>Index: gcc/doc/cpp.texi
>===================================================================
>--- gcc/doc/cpp.texi (revision 254145)
>+++ gcc/doc/cpp.texi (working copy)
>@@ -211,8 +211,8 @@ Standard C@. In its default mode, the GNU C prepr
> few things required by the standard. These are features which are
> rarely, if ever, used, and may cause surprising changes to the meaning
>of a program which does not expect them. To get strict ISO Standard C,
>-you should use the @option{-std=c90}, @option{-std=c99} or
>-@option{-std=c11} options, depending
>+you should use the @option{-std=c90}, @option{-std=c99},
>+@option{-std=c11} or @option{-std=c17} options, depending
> on which version of the standard you want. To get all the mandatory
> diagnostics, you must also use @option{-pedantic}. @xref{Invocation}.
>
>@@ -1857,8 +1857,11 @@ implementation, unless GNU CPP is being used
>with
>
> The value @code{199409L} signifies the 1989 C standard as amended in
> 1994, which is the current default; the value @code{199901L} signifies
>-the 1999 revision of the C standard. Support for the 1999 revision is
>-not yet complete.
>+the 1999 revision of the C standard; the value @code{201112L}
>+signifies the 2011 revision of the C standard; the value
>+@code{201710L} signifies the 2017 revision of the C standard (which is
>+otherwise identical to the 2011 version apart from correction of
>+defects).
>
> This macro is not defined if the @option{-traditional-cpp} option is
> used, nor when compiling C++ or Objective-C@.
>Index: gcc/doc/extend.texi
>===================================================================
>--- gcc/doc/extend.texi (revision 254145)
>+++ gcc/doc/extend.texi (working copy)
>@@ -7775,8 +7775,8 @@ GCC implements three different semantics of
>declar
> inline. One is available with @option{-std=gnu89} or
> @option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
> on all inline declarations, another when
>-@option{-std=c99}, @option{-std=c11},
>-@option{-std=gnu99} or @option{-std=gnu11}
>+@option{-std=c99},
>+@option{-std=gnu99} or an option for a later C version is used
> (without @option{-fgnu89-inline}), and the third
> is used when compiling C++.
>
>Index: gcc/doc/invoke.texi
>===================================================================
>--- gcc/doc/invoke.texi (revision 254145)
>+++ gcc/doc/invoke.texi (working copy)
>@@ -1831,6 +1831,13 @@ substantially completely supported, modulo bugs,
>f
> Annexes F and G) and the optional Annexes K (Bounds-checking
> interfaces) and L (Analyzability). The name @samp{c1x} is deprecated.
>
>+@item c17
>+@itemx iso9899:2017
>+ISO C17, the 2017 revision of the ISO C standard. This standard is
>+same as C11 except for corrections of defects (all of which are also
>+applied with @option{-std=c11}) and a new value of
>+@code{__STDC_VERSION__}, and so is supported to the same extent as
>C11.
>+
> @item gnu90
> @itemx gnu89
> GNU dialect of ISO C90 (including some C99 features).
>@@ -1841,9 +1848,12 @@ GNU dialect of ISO C99. The name @samp{gnu9x}
>is
>
> @item gnu11
> @itemx gnu1x
>-GNU dialect of ISO C11. This is the default for C code.
>+GNU dialect of ISO C11.
> The name @samp{gnu1x} is deprecated.
>
>+@item gnu17
>+GNU dialect of ISO C17. This is the default for C code.
>+
> @item c++98
> @itemx c++03
> The 1998 ISO C++ standard plus the 2003 technical corrigendum and some
>Index: gcc/doc/standards.texi
>===================================================================
>--- gcc/doc/standards.texi (revision 254145)
>+++ gcc/doc/standards.texi (working copy)
>@@ -36,6 +36,8 @@ with some exceptions, and possibly with some exten
> @cindex C11
> @cindex ISO C1X
> @cindex C1X
>+@cindex ISO C17
>+@cindex C17
> @cindex Technical Corrigenda
> @cindex TC1
> @cindex Technical Corrigendum 1
>@@ -100,7 +102,11 @@ in 2011 as ISO/IEC 9899:2011. (While in developme
> standard version were referred to as @dfn{C1X}.)
> GCC has substantially complete support
> for this standard, enabled with @option{-std=c11} or
>-@option{-std=iso9899:2011}.
>+@option{-std=iso9899:2011}. A version with corrections integrated is
>+known as @dfn{C17} and is supported with @option{-std=c17} or
>+@option{-std=iso9899:2017}; the corrections are also applied with
>+@option{-std=c11}, and the only difference between the options is the
>+value of @code{__STDC_VERSION__}.
>
> By default, GCC provides some extensions to the C language that, on
> rare occasions conflict with the C standard. @xref{C
>Index: gcc/dwarf2out.c
>===================================================================
>--- gcc/dwarf2out.c (revision 254145)
>+++ gcc/dwarf2out.c (working copy)
>@@ -23434,6 +23434,8 @@ highest_c_language (const char *lang1, const
>char
>if (strcmp ("GNU C++98", lang1) == 0 || strcmp ("GNU C++98", lang2) ==
>0)
> return "GNU C++98";
>
>+ if (strcmp ("GNU C17", lang1) == 0 || strcmp ("GNU C17", lang2) ==
>0)
>+ return "GNU C17";
> if (strcmp ("GNU C11", lang1) == 0 || strcmp ("GNU C11", lang2) == 0)
> return "GNU C11";
> if (strcmp ("GNU C99", lang1) == 0 || strcmp ("GNU C99", lang2) == 0)
>@@ -23510,7 +23512,8 @@ gen_compile_unit_die (const char *filename)
> language = DW_LANG_C99;
>
> if (dwarf_version >= 5 /* || !dwarf_strict */)
>- if (strcmp (language_string, "GNU C11") == 0)
>+ if (strcmp (language_string, "GNU C11") == 0
>+ || strcmp (language_string, "GNU C17") == 0)
> language = DW_LANG_C11;
> }
> }
>Index: gcc/testsuite/gcc.dg/c17-version-1.c
>===================================================================
>--- gcc/testsuite/gcc.dg/c17-version-1.c (nonexistent)
>+++ gcc/testsuite/gcc.dg/c17-version-1.c (working copy)
>@@ -0,0 +1,9 @@
>+/* Test __STDC_VERSION__ for C17. Test -std=c17. */
>+/* { dg-do compile } */
>+/* { dg-options "-std=c17 -pedantic-errors" } */
>+
>+#if __STDC_VERSION__ == 201710L
>+int i;
>+#else
>+#error "Bad __STDC_VERSION__."
>+#endif
>Index: gcc/testsuite/gcc.dg/c17-version-2.c
>===================================================================
>--- gcc/testsuite/gcc.dg/c17-version-2.c (nonexistent)
>+++ gcc/testsuite/gcc.dg/c17-version-2.c (working copy)
>@@ -0,0 +1,9 @@
>+/* Test __STDC_VERSION__ for C17. Test -std=iso9899:2017. */
>+/* { dg-do compile } */
>+/* { dg-options "-std=iso9899:2017 -pedantic-errors" } */
>+
>+#if __STDC_VERSION__ == 201710L
>+int i;
>+#else
>+#error "Bad __STDC_VERSION__."
>+#endif
>Index: libcpp/include/cpplib.h
>===================================================================
>--- libcpp/include/cpplib.h (revision 254145)
>+++ libcpp/include/cpplib.h (working copy)
>@@ -168,8 +168,8 @@ enum cpp_ttype
> #undef TK
>
> /* C language kind, used when calling cpp_create_reader. */
>-enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11,
>- CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11,
>+enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17,
>+ CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_STDC17,
> CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
> CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
> CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM};
>Index: libcpp/init.c
>===================================================================
>--- libcpp/init.c (revision 254145)
>+++ libcpp/init.c (working copy)
>@@ -98,10 +98,12 @@ static const struct lang_flags lang_defaults[] =
>/* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
>0, 0, 0 },
>/* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0,
>0, 0, 0 },
>/* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0,
>0, 0, 0 },
>+ /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0,
> 0, 0, 0 },
>/* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
>0, 1, 0 },
>/* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
>0, 1, 0 },
>/* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0,
>0, 1, 0 },
>/* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0,
>0, 1, 0 },
>+ /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0,
> 0, 1, 0 },
>/* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0,
>0, 0, 0 },
>/* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0,
>0, 1, 0 },
>/* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0,
>0, 0, 0 },
>@@ -518,6 +520,9 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
> _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
> else if (CPP_OPTION (pfile, lang) == CLK_STDC94)
> _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
>+ else if (CPP_OPTION (pfile, lang) == CLK_STDC17
>+ || CPP_OPTION (pfile, lang) == CLK_GNUC17)
>+ _cpp_define_builtin (pfile, "__STDC_VERSION__ 201710L");
> else if (CPP_OPTION (pfile, lang) == CLK_STDC11
> || CPP_OPTION (pfile, lang) == CLK_GNUC11)
> _cpp_define_builtin (pfile, "__STDC_VERSION__ 201112L");
prev parent reply other threads:[~2017-10-28 17:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-27 22:04 Joseph Myers
2017-10-28 21:57 ` Richard Biener [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=F876A3D9-47A3-4A34-9A3D-D2DB45687CBB@gmail.com \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).