From patchwork Fri Oct 27 21:56:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 831521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-465397-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="bM1LX5Oq"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yNyQb0HXYz9sNd for ; Sat, 28 Oct 2017 08:57:10 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=CnCs+a108rOgXJuW1jkIlmV8RSu/TqFZhq6VH94kx8YpAvnPEHISc CI0lF6Xr+fb2zXIe60dOv9BlSvLjW5Eb7tUJ30Zdehpvs4TDpfGOiF/JZQu18FRY DA0zCKU3EwG6exskotF2rE9qKGcsx572LU8ZyD2hfGDsKiueZ3yl4E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=3WooJqGJ7umKkOr4YhdbJb+eMOc=; b=bM1LX5Oqf++gdr+XB+AM p7aXvRvr9u3gW1HuBd61SoaRtm3EyQ3Ovx2zCG3sT6TbJ0p62PuwrejgEFrDtW5G j3MAcDZbgFKoedZNJGu1UnHhEeXs/K+4vS1BD/Wh6b+3HuIdyL29873H/b+LPzTM kNasNjocbGrdTKf8bl5tEw8= Received: (qmail 62173 invoked by alias); 27 Oct 2017 21:57:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 62153 invoked by uid 89); 27 Oct 2017 21:57:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=publication, ballot, occasions, 6756 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Oct 2017 21:56:58 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-03.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1e8CcY-00049u-Vh from joseph_myers@mentor.com for gcc-patches@gcc.gnu.org; Fri, 27 Oct 2017 14:56:55 -0700 Received: from digraph.polyomino.org.uk (137.202.0.87) by SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Fri, 27 Oct 2017 22:56:51 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.86_2) (envelope-from ) id 1e8CcR-0003Rj-IA for gcc-patches@gcc.gnu.org; Fri, 27 Oct 2017 21:56:47 +0000 Date: Fri, 27 Oct 2017 21:56:47 +0000 From: Joseph Myers To: Subject: Add -std=c17, -std=gnu17 Message-ID: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) 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? gcc: 2017-10-27 Joseph Myers * 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 * 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 * gcc.dg/c17-version-1.c, gcc.dg/c17-version-2.c: New tests. libcpp: 2017-10-27 Joseph Myers * 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");