Move the "needs exception support" logic to clang. This also fixes
-fno-exceptions in C++ code. We used to always define __EXCEPTIONS in
C++.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83199 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 1044e02..ac7df86 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -472,6 +472,31 @@
}
}
+static bool needsExceptions(const ArgList &Args, types::ID InputType) {
+ if (Arg *A = Args.getLastArg(options::OPT_fexceptions,
+ options::OPT_fno_exceptions)) {
+ if (A->getOption().matches(options::OPT_fexceptions))
+ return true;
+ else
+ return false;
+ }
+ switch (InputType) {
+ case types::TY_CXX: case types::TY_CXXHeader:
+ case types::TY_PP_CXX: case types::TY_PP_CXXHeader:
+ case types::TY_ObjCXX: case types::TY_ObjCXXHeader:
+ case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader:
+ return true;
+ case types::TY_ObjC: case types::TY_ObjCHeader:
+ case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader:
+ if (Args.hasArg(options::OPT_fobjc_nonfragile_abi))
+ return true;
+ else
+ return false;
+ default:
+ return false;
+ }
+}
+
void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Job &Dest,
const InputInfo &Output,
@@ -808,15 +833,10 @@
CmdArgs.push_back("-fblocks=0");
}
- // -fexceptions default varies depending on platform and language; only
- // pass if specified.
- if (Arg *A = Args.getLastArg(options::OPT_fexceptions,
- options::OPT_fno_exceptions)) {
- if (A->getOption().matches(options::OPT_fexceptions))
- CmdArgs.push_back("-fexceptions");
- else
- CmdArgs.push_back("-fexceptions=0");
- }
+ if (needsExceptions(Args, InputType))
+ CmdArgs.push_back("-fexceptions");
+ else
+ CmdArgs.push_back("-fexceptions=0");
// -frtti is default, only pass non-default.
if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti))
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index 6c8a8c1..0f3b4b8 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -274,7 +274,6 @@
if (LangOpts.ObjCNonFragileABI) {
DefineBuiltinMacro(Buf, "__OBJC2__=1");
DefineBuiltinMacro(Buf, "OBJC_ZEROCOST_EXCEPTIONS=1");
- DefineBuiltinMacro(Buf, "__EXCEPTIONS=1");
}
if (LangOpts.getGCMode() != LangOptions::NonGC)
@@ -299,9 +298,11 @@
DefineBuiltinMacro(Buf, "__BLOCKS__=1");
}
+ if (LangOpts.Exceptions)
+ DefineBuiltinMacro(Buf, "__EXCEPTIONS=1");
+
if (LangOpts.CPlusPlus) {
DefineBuiltinMacro(Buf, "__DEPRECATED=1");
- DefineBuiltinMacro(Buf, "__EXCEPTIONS=1");
DefineBuiltinMacro(Buf, "__GNUG__=4");
DefineBuiltinMacro(Buf, "__GXX_WEAK__=1");
if (LangOpts.GNUMode)