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.

llvm-svn: 220244
This commit is contained in:
Richard Smith 2014-10-20 23:26:58 +00:00
parent e6b994eb93
commit ab506adf7d
14 changed files with 52 additions and 38 deletions

View File

@ -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!).

View File

@ -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");

View File

@ -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:

View File

@ -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)

View File

@ -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();

View File

@ -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}}

View File

@ -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;

View File

@ -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

View File

@ -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'

View File

@ -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;

View File

@ -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)}}

View File

@ -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}}

View File

@ -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

View File

@ -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