diff --git a/docs/UsersManual.rst b/docs/UsersManual.rst index a5d81488102bd081e0124f069b2ee9e2399fa6f8..9d8e978ed3695ce866208bbd69136bf98cf0d22c 100644 --- a/docs/UsersManual.rst +++ b/docs/UsersManual.rst @@ -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 modes ------------------------------------------ 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`` modes: 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!). diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 2798601a51fb2f9da3386b9d62e89a23c6716ee9..957448a2d494e5d5ad57239d94886c597b87eaaf 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -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"); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 19eecdbaedfb4f10b0fde6ebf76fb47f39e62b1f..373842d238173e8011fd64e55b2fde17af205259 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1129,7 +1129,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, case IK_PreprocessedC: case IK_ObjC: case IK_PreprocessedObjC: - LangStd = LangStandard::lang_gnu99; + LangStd = LangStandard::lang_gnu11; break; case IK_CXX: case IK_PreprocessedCXX: diff --git a/test/Lexer/has_extension.c b/test/Lexer/has_extension.c index 3b08510aa4402184a7c7774e552f7a0fc7e3653f..2ab3d1df37a8193fd23ddb96f24c54c5cac6d425 100644 --- a/test/Lexer/has_extension.c +++ b/test/Lexer/has_extension.c @@ -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) diff --git a/test/Lexer/has_feature_c1x.c b/test/Lexer/has_feature_c1x.c index e26e309c037101ecf7fcb4501bb34e721985285c..cba329cfb5501aaa2f73e9620afc325b33c1f200 100644 --- a/test/Lexer/has_feature_c1x.c +++ b/test/Lexer/has_feature_c1x.c @@ -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(); diff --git a/test/Parser/c11-noreturn.c b/test/Parser/c11-noreturn.c index e61901dfb7918077c25ced82fb56a309cc0b7e39..6c01b5533acfcfccf29f579c0699561f273070a2 100644 --- a/test/Parser/c11-noreturn.c +++ b/test/Parser/c11-noreturn.c @@ -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}} diff --git a/test/Parser/c1x-alignas.c b/test/Parser/c1x-alignas.c index 5b29df262d3ca82950643fe219a4b2f1a9318a64..ce8436c12fbb8c640bb3ad7db26fd2814fd283c3 100644 --- a/test/Parser/c1x-alignas.c +++ b/test/Parser/c1x-alignas.c @@ -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; diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index b45c2c944a16d6f8fc5ee88d88b0c3fefb644a3b..1afdbcaaa94f0e9e42f6be4e551419b0e7feac7f 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -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 diff --git a/test/Preprocessor/line-directive.c b/test/Preprocessor/line-directive.c index 0dd658f7f1a1333127b85d510f77c795ab75aef1..2ebe87e4680d09b6c6a021f00b66b525d19c8529 100644 --- a/test/Preprocessor/line-directive.c +++ b/test/Preprocessor/line-directive.c @@ -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' diff --git a/test/Sema/anonymous-struct-union-c11.c b/test/Sema/anonymous-struct-union-c11.c index 229ee520575e11f7f3beab01e3aded11129c4ecb..712e29e5496a37cd6533f3d82543066c8cf34ec9 100644 --- a/test/Sema/anonymous-struct-union-c11.c +++ b/test/Sema/anonymous-struct-union-c11.c @@ -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; diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c index 4cc5e412c2d557d99033b5afb6a05be2cf23f008..7cb48153168fb046fd34e2dce550fe99e24bdeaf 100644 --- a/test/Sema/array-init.c +++ b/test/Sema/array-init.c @@ -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)}} diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index c9e3dd546c581f13597a0a1bc6da0f9ea7c96e79..2e3e722942a0f88a8d5907ad9c6103d586f4de24 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -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}} diff --git a/test/Sema/types.c b/test/Sema/types.c index 6a22b20b0ea45983d41590310a03c2b23d0b669d..1ed8dae4c805d1c2eea608e5280ddd308ec2739c 100644 --- a/test/Sema/types.c +++ b/test/Sema/types.c @@ -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 diff --git a/www/compatibility.html b/www/compatibility.html index 8bfaff191cb5b39f1120f72fa5c0ac8c0c507d5a..293be6f2203283b6124b0ad1b6a921b6e3f5d9f8 100644 --- a/www/compatibility.html +++ b/www/compatibility.html @@ -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 optimizer.</p> 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