r220244 - Switch C compilations to C11 by default.

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Oct 20 17:37:56 PDT 2014


nice :-)

On 20 October 2014 19:26, Richard Smith <richard-llvm at metafoo.co.uk> wrote:
> Author: rsmith
> Date: Mon Oct 20 18:26:58 2014
> New Revision: 220244
>
> URL: http://llvm.org/viewvc/llvm-project?rev=220244&view=rev
> Log:
> Switch C compilations to C11 by default.
>
> This is long-since overdue, and matches GCC 5.0. This should also be
> backwards-compatible, because we already supported all of C11 as an extension
> in C99 mode.
>
> Modified:
>     cfe/trunk/docs/UsersManual.rst
>     cfe/trunk/lib/Basic/Targets.cpp
>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>     cfe/trunk/test/Lexer/has_extension.c
>     cfe/trunk/test/Lexer/has_feature_c1x.c
>     cfe/trunk/test/Parser/c11-noreturn.c
>     cfe/trunk/test/Parser/c1x-alignas.c
>     cfe/trunk/test/Preprocessor/init.c
>     cfe/trunk/test/Preprocessor/line-directive.c
>     cfe/trunk/test/Sema/anonymous-struct-union-c11.c
>     cfe/trunk/test/Sema/array-init.c
>     cfe/trunk/test/Sema/attr-deprecated.c
>     cfe/trunk/test/Sema/types.c
>     cfe/trunk/www/compatibility.html
>
> Modified: cfe/trunk/docs/UsersManual.rst
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/docs/UsersManual.rst (original)
> +++ cfe/trunk/docs/UsersManual.rst Mon Oct 20 18:26:58 2014
> @@ -73,7 +73,7 @@ Basic Usage
>  Intro to how to use a C compiler for newbies.
>
>  compile + link compile then link debug info enabling optimizations
> -picking a language to use, defaults to C99 by default. Autosenses based
> +picking a language to use, defaults to C11 by default. Autosenses based
>  on extension. using a makefile
>
>  Command Line Options
> @@ -1474,9 +1474,12 @@ Differences between various standard mod
>  ------------------------------------------
>
>  clang supports the -std option, which changes what language mode clang
> -uses. The supported modes for C are c89, gnu89, c94, c99, gnu99 and
> -various aliases for those modes. If no -std option is specified, clang
> -defaults to gnu99 mode.
> +uses. The supported modes for C are c89, gnu89, c94, c99, gnu99, c11,
> +gnu11, and various aliases for those modes. If no -std option is
> +specified, clang defaults to gnu11 mode. Many C99 and C11 features are
> +supported in earlier modes as a conforming extension, with a warning. Use
> +``-pedantic-errors`` to request an error if a feature from a later standard
> +revision is used in an earlier mode.
>
>  Differences between all ``c*`` and ``gnu*`` modes:
>
> @@ -1514,6 +1517,11 @@ Differences between ``*89`` and ``*99``
>     in ``*89`` modes.
>  -  Some warnings are different.
>
> +Differences between ``*99`` and ``*11`` modes:
> +
> +-  Warnings for use of C11 features are disabled.
> +-  ``__STDC_VERSION__`` is defined to ``201112L`` rather than ``199901L``.
> +
>  c94 mode is identical to c89 mode except that digraphs are enabled in
>  c94 mode (FIXME: And ``__STDC_VERSION__`` should be defined!).
>
>
> Modified: cfe/trunk/lib/Basic/Targets.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Targets.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets.cpp Mon Oct 20 18:26:58 2014
> @@ -531,8 +531,8 @@ protected:
>      // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
>      // newer, but to 500 for everything else.  feature_test.h has a check to
>      // ensure that you are not using C99 with an old version of X/Open or C89
> -    // with a new version.
> -    if (Opts.C99 || Opts.C11)
> +    // with a new version.
> +    if (Opts.C99)
>        Builder.defineMacro("_XOPEN_SOURCE", "600");
>      else
>        Builder.defineMacro("_XOPEN_SOURCE", "500");
> @@ -4584,7 +4584,7 @@ public:
>      if (Opts.FastMath || Opts.FiniteMathOnly)
>        Builder.defineMacro("__ARM_FP_FAST");
>
> -    if ((Opts.C99 || Opts.C11) && !Opts.Freestanding)
> +    if (Opts.C99 && !Opts.Freestanding)
>        Builder.defineMacro("__ARM_FP_FENV_ROUNDING");
>
>      Builder.defineMacro("__ARM_SIZEOF_WCHAR_T", Opts.ShortWChar ? "2" : "4");
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Oct 20 18:26:58 2014
> @@ -1129,7 +1129,7 @@ void CompilerInvocation::setLangDefaults
>      case IK_PreprocessedC:
>      case IK_ObjC:
>      case IK_PreprocessedObjC:
> -      LangStd = LangStandard::lang_gnu99;
> +      LangStd = LangStandard::lang_gnu11;
>        break;
>      case IK_CXX:
>      case IK_PreprocessedCXX:
>
> Modified: cfe/trunk/test/Lexer/has_extension.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/has_extension.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Lexer/has_extension.c (original)
> +++ cfe/trunk/test/Lexer/has_extension.c Mon Oct 20 18:26:58 2014
> @@ -1,5 +1,5 @@
> -// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-PED-NONE %s
> -// RUN: %clang_cc1 -pedantic-errors -E %s -o - | FileCheck --check-prefix=CHECK-PED-ERR %s
> +// RUN: %clang_cc1 -std=c99 -E %s -o - | FileCheck --check-prefix=CHECK-PED-NONE %s
> +// RUN: %clang_cc1 -std=c99 -pedantic-errors -E %s -o - | FileCheck --check-prefix=CHECK-PED-ERR %s
>
>  // CHECK-PED-NONE: no_dummy_extension
>  #if !__has_extension(dummy_extension)
>
> Modified: cfe/trunk/test/Lexer/has_feature_c1x.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/has_feature_c1x.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Lexer/has_feature_c1x.c (original)
> +++ cfe/trunk/test/Lexer/has_feature_c1x.c Mon Oct 20 18:26:58 2014
> @@ -1,5 +1,11 @@
> -// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=c1x %s -o - | FileCheck --check-prefix=CHECK-1X %s
> -// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-1X %s
> +// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=c89 %s -o - | FileCheck --check-prefix=CHECK-NO-1X %s
> +// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=iso9899:199409 %s -o - | FileCheck --check-prefix=CHECK-NO-1X %s
> +// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=c99 %s -o - | FileCheck --check-prefix=CHECK-NO-1X %s
> +// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=c11 %s -o - | FileCheck --check-prefix=CHECK-1X %s
> +//
> +// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=gnu89 %s -o - | FileCheck --check-prefix=CHECK-NO-1X %s
> +// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=gnu99 %s -o - | FileCheck --check-prefix=CHECK-NO-1X %s
> +// RUN: %clang_cc1 -E -triple x86_64-linux-gnu -std=gnu11 %s -o - | FileCheck --check-prefix=CHECK-1X %s
>
>  #if __has_feature(c_atomic)
>  int has_atomic();
>
> Modified: cfe/trunk/test/Parser/c11-noreturn.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/c11-noreturn.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Parser/c11-noreturn.c (original)
> +++ cfe/trunk/test/Parser/c11-noreturn.c Mon Oct 20 18:26:58 2014
> @@ -1,5 +1,5 @@
>  // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
> -// RUN: not %clang_cc1 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s
> +// RUN: not %clang_cc1 -std=c99 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s
>
>  _Noreturn int f();
>  int _Noreturn f(); // expected-note {{previous}}
>
> Modified: cfe/trunk/test/Parser/c1x-alignas.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/c1x-alignas.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Parser/c1x-alignas.c (original)
> +++ cfe/trunk/test/Parser/c1x-alignas.c Mon Oct 20 18:26:58 2014
> @@ -1,5 +1,5 @@
>  // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
> -// RUN: not %clang_cc1 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s
> +// RUN: not %clang_cc1 -std=c99 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s
>
>  _Alignas(4) char c1;
>  unsigned _Alignas(long) char c2;
>
> Modified: cfe/trunk/test/Preprocessor/init.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/init.c (original)
> +++ cfe/trunk/test/Preprocessor/init.c Mon Oct 20 18:26:58 2014
> @@ -80,7 +80,7 @@
>  // COMMON:#define __ORDER_LITTLE_ENDIAN__ 1234
>  // COMMON:#define __ORDER_PDP_ENDIAN__ 3412
>  // COMMON:#define __STDC_HOSTED__ 1
> -// COMMON:#define __STDC_VERSION__
> +// COMMON:#define __STDC_VERSION__ 201112L
>  // COMMON:#define __STDC__ 1
>  // COMMON:#define __VERSION__
>  // COMMON:#define __clang__ 1
> @@ -2546,7 +2546,7 @@
>  // MIPS32BE:#define __SIZE_TYPE__ unsigned int
>  // MIPS32BE:#define __SIZE_WIDTH__ 32
>  // MIPS32BE:#define __STDC_HOSTED__ 0
> -// MIPS32BE:#define __STDC_VERSION__ 199901L
> +// MIPS32BE:#define __STDC_VERSION__ 201112L
>  // MIPS32BE:#define __STDC__ 1
>  // MIPS32BE:#define __UINT16_C_SUFFIX__ {{$}}
>  // MIPS32BE:#define __UINT16_MAX__ 65535
> @@ -5458,7 +5458,7 @@
>  // PPC-DARWIN:#define __SIZE_TYPE__ long unsigned int
>  // PPC-DARWIN:#define __SIZE_WIDTH__ 32
>  // PPC-DARWIN:#define __STDC_HOSTED__ 0
> -// PPC-DARWIN:#define __STDC_VERSION__ 199901L
> +// PPC-DARWIN:#define __STDC_VERSION__ 201112L
>  // PPC-DARWIN:#define __STDC__ 1
>  // PPC-DARWIN:#define __UINT16_C_SUFFIX__ {{$}}
>  // PPC-DARWIN:#define __UINT16_MAX__ 65535
>
> Modified: cfe/trunk/test/Preprocessor/line-directive.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Preprocessor/line-directive.c (original)
> +++ cfe/trunk/test/Preprocessor/line-directive.c Mon Oct 20 18:26:58 2014
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
> +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify -pedantic %s
>  // RUN: not %clang_cc1 -E %s 2>&1 | grep 'blonk.c:92:2: error: ABC'
>  // RUN: not %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: DEF'
>
>
> Modified: cfe/trunk/test/Sema/anonymous-struct-union-c11.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/anonymous-struct-union-c11.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/anonymous-struct-union-c11.c (original)
> +++ cfe/trunk/test/Sema/anonymous-struct-union-c11.c Mon Oct 20 18:26:58 2014
> @@ -1,8 +1,8 @@
>  // Check for warnings in non-C11 mode:
> -// RUN: %clang_cc1 -fsyntax-only -verify -Wc11-extensions %s
> +// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -Wc11-extensions %s
>
>  // Expect no warnings in C11 mode:
> -// RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -std=c11 %s
> +// RUN: %clang_cc1 -fsyntax-only -std=c11 -pedantic -Werror %s
>
>  struct s {
>    int a;
>
> Modified: cfe/trunk/test/Sema/array-init.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/array-init.c (original)
> +++ cfe/trunk/test/Sema/array-init.c Mon Oct 20 18:26:58 2014
> @@ -1,5 +1,5 @@
> -// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
> -// RUN: %clang_cc1 -fsyntax-only -Wgnu -Wc11-extensions -verify %s
> +// RUN: %clang_cc1 -std=gnu99 -fsyntax-only -pedantic -verify %s
> +// RUN: %clang_cc1 -std=gnu99 -fsyntax-only -Wgnu -Wc11-extensions -verify %s
>  // REQUIRES: LP64
>
>  extern int foof() = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
>
> Modified: cfe/trunk/test/Sema/attr-deprecated.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-deprecated.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/attr-deprecated.c (original)
> +++ cfe/trunk/test/Sema/attr-deprecated.c Mon Oct 20 18:26:58 2014
> @@ -121,6 +121,6 @@ struct test22 {
>    __attribute((deprecated)) foo_dep e, f;
>  };
>
> -typedef int test23_ty __attribute((deprecated)); // expected-note {{previous definition is here}}
> -typedef int test23_ty; // expected-note {{'test23_ty' has been explicitly marked deprecated here}} expected-warning {{redefinition of typedef 'test23_ty' is a C11 feature}}
> +typedef int test23_ty __attribute((deprecated));
> +typedef int test23_ty; // expected-note {{'test23_ty' has been explicitly marked deprecated here}}
>  test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}}
>
> Modified: cfe/trunk/test/Sema/types.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/types.c?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/types.c (original)
> +++ cfe/trunk/test/Sema/types.c Mon Oct 20 18:26:58 2014
> @@ -30,12 +30,12 @@ int c() {
>    int __int128; // expected-error {{cannot combine with previous}} expected-warning {{does not declare anything}}
>  }
>  // __int128_t is __int128; __uint128_t is unsigned __int128.
> -typedef __int128 check_int_128; // expected-note {{here}}
> -typedef __int128_t check_int_128; // expected-note {{here}} expected-warning {{redefinition}}
> +typedef __int128 check_int_128;
> +typedef __int128_t check_int_128; // expected-note {{here}}
>  typedef int check_int_128; // expected-error {{different types ('int' vs '__int128_t' (aka '__int128'))}}
>
> -typedef unsigned __int128 check_uint_128; // expected-note {{here}}
> -typedef __uint128_t check_uint_128; // expected-note {{here}} expected-warning {{redefinition}}
> +typedef unsigned __int128 check_uint_128;
> +typedef __uint128_t check_uint_128; // expected-note {{here}}
>  typedef int check_uint_128; // expected-error {{different types ('int' vs '__uint128_t' (aka 'unsigned __int128'))}}
>
>  // Array type merging should convert array size to whatever matches the target
>
> Modified: cfe/trunk/www/compatibility.html
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/compatibility.html?rev=220244&r1=220243&r2=220244&view=diff
> ==============================================================================
> --- cfe/trunk/www/compatibility.html (original)
> +++ cfe/trunk/www/compatibility.html Mon Oct 20 18:26:58 2014
> @@ -83,10 +83,10 @@
>  <!-- ======================================================================= -->
>  <h3 id="inline">C99 inline functions</h3>
>  <!-- ======================================================================= -->
> -<p>By default, Clang builds C code according to the C99 standard,
> -which provides different semantics for the <code>inline</code> keyword
> -than GCC's default behavior. For example, consider the following
> -code:</p>
> +<p>By default, Clang builds C code in GNU C11 mode, so it uses standard C99
> +semantics for the <code>inline</code> keyword. These semantics are different
> +from those in GNU C89 mode, which is the default mode in versions of GCC
> +prior to 5.0. For example, consider the following code:</p>
>  <pre>
>  inline int add(int i, int j) { return i + j; }
>
> @@ -110,10 +110,10 @@ Undefined symbols:
>        _main in cc-y1jXIr.o
>  </pre>
>
> -<p>By contrast, GCC's default behavior follows the GNU89 dialect,
> -which is the C89 standard plus a lot of extensions.  C89 doesn't have
> -an <code>inline</code> keyword, but GCC recognizes it as an extension
> -and just treats it as a hint to the optimizer.</p>
> +<p>By contrast, GNU C89 mode (used by default in older versions of GCC) is the
> +C89 standard plus a lot of extensions. C89 doesn't have an <code>inline</code>
> +keyword, but GCC recognizes it as an extension and just treats it as a hint to
> +the optimizer.</p>
>
>  <p>There are several ways to fix this problem:</p>
>
> @@ -130,12 +130,12 @@ and just treats it as a hint to the opti
>    for a function to be inlined, nor does it guarantee that it will be.
>    Some compilers ignore it completely.  Clang treats it as a mild
>    suggestion from the programmer.</li>
> -
> +
>    <li>Provide an external (non-<code>inline</code>) definition
>    of <code>add</code> somewhere else in your program.  The two
>    definitions must be equivalent!</li>
>
> -  <li>Compile with the GNU89 dialect by adding
> +  <li>Compile in the GNU C89 dialect by adding
>    <code>-std=gnu89</code> to the set of Clang options. This option is
>    only recommended if the program source cannot be changed or if the
>    program also relies on additional C89-specific behavior that cannot
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list