summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorMichal Gorny <mgorny@gentoo.org>2018-03-06 21:26:28 +0000
committerMichal Gorny <mgorny@gentoo.org>2018-03-06 21:26:28 +0000
commit4289f4cecf673808f870f66074bfc7a24eb5f580 (patch)
treee4d967acafd41ff30f6fbdf3af5cb29cb24650a4 /clang/lib/Frontend/CompilerInvocation.cpp
parent09fcd4c34c58e0bd9f372e97abd717ba5b4c11d3 (diff)
downloadbcm5719-llvm-4289f4cecf673808f870f66074bfc7a24eb5f580.tar.gz
bcm5719-llvm-4289f4cecf673808f870f66074bfc7a24eb5f580.zip
[FrontEnd] Allow overriding the default C/C++ -std via CMake vars
Provide two new CMake cache variables -- CLANG_DEFAULT_STD_C and CLANG_DEFAULT_STD_CXX -- that can be used to override the default C/ObjC and C++/ObjC++ standards appropriately. They can be set to one of the identifiers from LangStandards.def, or left unset (the default) to respect the current platform default. This option is mostly intended for compiler vendors that may wish to adjust the defaults their compilers are using. For example, Gentoo planned to use it to set clang and gcc to matching standards, so that we could maintain as much compatibility between different compilers as possible. The code relies on explicit identifiers rather than the string aliases for simplicity. This saves us from the necessity of parsing aliases at build-time or adding additional processing at runtime. For the latter case, it also adds trivial value check -- if incorrect value is passed, the code simply fails to compile through referencing an undefined constant. If the variable is used to redefine the default standard, the explicit value overrides the special case for PS4. It is done this way mostly following other kinds of variables where 'platform defaults' are redefined. Differential Revision: https://reviews.llvm.org/D34365 llvm-svn: 326836
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 23f3c8fbbdc..ff8db474e18 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1809,18 +1809,30 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
break;
case InputKind::Asm:
case InputKind::C:
+#if defined(CLANG_DEFAULT_STD_C)
+ LangStd = CLANG_DEFAULT_STD_C;
+#else
// The PS4 uses C99 as the default C standard.
if (T.isPS4())
LangStd = LangStandard::lang_gnu99;
else
LangStd = LangStandard::lang_gnu11;
+#endif
break;
case InputKind::ObjC:
+#if defined(CLANG_DEFAULT_STD_C)
+ LangStd = CLANG_DEFAULT_STD_C;
+#else
LangStd = LangStandard::lang_gnu11;
+#endif
break;
case InputKind::CXX:
case InputKind::ObjCXX:
+#if defined(CLANG_DEFAULT_STD_CXX)
+ LangStd = CLANG_DEFAULT_STD_CXX;
+#else
LangStd = LangStandard::lang_gnucxx14;
+#endif
break;
case InputKind::RenderScript:
LangStd = LangStandard::lang_c99;
OpenPOWER on IntegriCloud