<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 10, 2015 at 3:25 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:reid@kleckner.net" target="_blank">reid@kleckner.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Fri Jul 10 17:25:44 2015<br>
New Revision: 241952<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D241952-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=43o64PHy3PY8fHJJNk57N4dKCjTig5KKi1cqeZpMalA&s=O0MLvnqUJxG7KxnI0pjrsDPb7T4jFApDMs_sXczWSxU&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=241952&view=rev</a><br>
Log:<br>
Disable C++ EH by default for clang-cl and MSVC environments<br>
<br>
We don't need any more bug reports from users telling us that MSVC-style<br>
C++ exceptions are broken. Developers and adventurous users can still<br>
test the existing functionality by passing along -fexceptions to either<br>
clang or clang-cl.<br></blockquote><div><br></div><div>Cool. Is it really worth it to make -fexceptions a core option though? One day, exceptions will work and then /EHsc does the right thing. Until then, regular users shouldn't use -fexceptions, and irregular users can use -Xclang -fexceptions (which makes this look unsupported, just like it is).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
cfe/trunk/include/clang/Driver/Options.td<br>
cfe/trunk/lib/Driver/Tools.cpp<br>
cfe/trunk/test/Driver/cl-eh.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Driver/Options.td<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Driver_Options.td-3Frev-3D241952-26r1-3D241951-26r2-3D241952-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=43o64PHy3PY8fHJJNk57N4dKCjTig5KKi1cqeZpMalA&s=cXiizFtaARx3-uJi6t7tHlzsaVECotKjJWwqRBfOz5s&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=241952&r1=241951&r2=241952&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jul 10 17:25:44 2015<br>
@@ -506,7 +506,7 @@ def femit_all_decls : Flag<["-"], "femit<br>
HelpText<"Emit all declarations, even if unused">;<br>
def fencoding_EQ : Joined<["-"], "fencoding=">, Group<f_Group>;<br>
def ferror_limit_EQ : Joined<["-"], "ferror-limit=">, Group<f_Group>, Flags<[CoreOption]>;<br>
-def fexceptions : Flag<["-"], "fexceptions">, Group<f_Group>, Flags<[CC1Option]>,<br>
+def fexceptions : Flag<["-"], "fexceptions">, Group<f_Group>, Flags<[CC1Option, CoreOption]>,<br>
HelpText<"Enable support for exception handling">;<br>
def fexcess_precision_EQ : Joined<["-"], "fexcess-precision=">,<br>
Group<clang_ignored_gcc_optimization_f_Group>;<br>
<br>
Modified: cfe/trunk/lib/Driver/Tools.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Driver_Tools.cpp-3Frev-3D241952-26r1-3D241951-26r2-3D241952-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=43o64PHy3PY8fHJJNk57N4dKCjTig5KKi1cqeZpMalA&s=Jfj19t06RiIjG7CXmFEjPbQHyC3ubNhhSUJClOlGy5g&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=241952&r1=241951&r2=241952&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Jul 10 17:25:44 2015<br>
@@ -2041,17 +2041,6 @@ shouldUseExceptionTablesForObjCException<br>
Triple.getArch() == llvm::Triple::arm));<br>
}<br>
<br>
-// exceptionSettings() exists to share the logic between -cc1 and linker<br>
-// invocations.<br>
-static bool exceptionSettings(const ArgList &Args, const llvm::Triple &Triple) {<br>
- if (Arg *A = Args.getLastArg(options::OPT_fexceptions,<br>
- options::OPT_fno_exceptions))<br>
- if (A->getOption().matches(options::OPT_fexceptions))<br>
- return true;<br>
-<br>
- return false;<br>
-}<br>
-<br>
/// Adds exception related arguments to the driver command arguments. There's a<br>
/// master flag, -fexceptions and also language specific flags to enable/disable<br>
/// C++ and Objective-C exceptions. This makes it possible to for example<br>
@@ -2075,8 +2064,9 @@ static void addExceptionArgs(const ArgLi<br>
return;<br>
}<br>
<br>
- // Gather the exception settings from the command line arguments.<br>
- bool EH = exceptionSettings(Args, Triple);<br>
+ // See if the user explicitly enabled exceptions.<br>
+ bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,<br>
+ false);<br>
<br>
// Obj-C exceptions are enabled by default, regardless of -fexceptions. This<br>
// is not necessarily sensible, but follows GCC.<br>
@@ -2089,8 +2079,11 @@ static void addExceptionArgs(const ArgLi<br>
}<br>
<br>
if (types::isCXX(InputType)) {<br>
- bool CXXExceptionsEnabled =<br>
- Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU();<br>
+ // Disable C++ EH by default on XCore, PS4, and MSVC.<br>
+ // FIXME: Remove MSVC from this list once things work.<br>
+ bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore &&<br>
+ !Triple.isPS4CPU() &&<br>
+ !Triple.isWindowsMSVCEnvironment();<br>
Arg *ExceptionArg = Args.getLastArg(<br>
options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,<br>
options::OPT_fexceptions, options::OPT_fno_exceptions);<br>
@@ -5040,6 +5033,7 @@ struct EHFlags {<br>
/// The default is /EHs-c-, meaning cleanups are disabled.<br>
static EHFlags parseClangCLEHFlags(const Driver &D, const ArgList &Args) {<br>
EHFlags EH;<br>
+<br>
std::vector<std::string> EHArgs =<br>
Args.getAllArgValues(options::OPT__SLASH_EH);<br>
for (auto EHVal : EHArgs) {<br>
@@ -5061,6 +5055,15 @@ static EHFlags parseClangCLEHFlags(const<br>
break;<br>
}<br>
}<br>
+<br>
+ // Only enable C++ exceptions if the user opts into it by passing<br>
+ // -fexceptions. Lots of build systems implicitly pass /EHsc when users don't<br>
+ // actually need it.<br>
+ // FIXME: Remove this when they work out of the box.<br>
+ if (!Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,<br>
+ /*default=*/false))<br>
+ EH = EHFlags();<br>
+<br>
return EH;<br>
}<br>
<br>
@@ -9102,7 +9105,9 @@ void XCore::Linker::ConstructJob(Compila<br>
if (Args.hasArg(options::OPT_v))<br>
CmdArgs.push_back("-v");<br>
<br>
- if (exceptionSettings(Args, getToolChain().getTriple()))<br>
+ // Pass -fexceptions through to the linker if it was present.<br>
+ if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,<br>
+ false))<br>
CmdArgs.push_back("-fexceptions");<br>
<br>
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);<br>
<br>
Modified: cfe/trunk/test/Driver/cl-eh.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_Driver_cl-2Deh.cpp-3Frev-3D241952-26r1-3D241951-26r2-3D241952-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=43o64PHy3PY8fHJJNk57N4dKCjTig5KKi1cqeZpMalA&s=SkEI3NwsNDaDVEeni5zLBt-4bUAkHlWkvPscQpwI6U8&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-eh.cpp?rev=241952&r1=241951&r2=241952&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Driver/cl-eh.cpp (original)<br>
+++ cfe/trunk/test/Driver/cl-eh.cpp Fri Jul 10 17:25:44 2015<br>
@@ -4,9 +4,13 @@<br>
// Note: %s must be preceded by --, otherwise it may be interpreted as a<br>
// command-line option, e.g. on Mac where %s is commonly under /Users.<br>
<br>
+// RUN: %clang_cl /c /EHsc -fexceptions -### -- %s 2>&1 | FileCheck -check-prefix=EHscfex %s<br>
+// EHscfex: "-fcxx-exceptions"<br>
+// EHscfex: "-fexceptions"<br>
+<br>
// RUN: %clang_cl /c /EHsc -### -- %s 2>&1 | FileCheck -check-prefix=EHsc %s<br>
-// EHsc: "-fcxx-exceptions"<br>
-// EHsc: "-fexceptions"<br>
+// EHsc-NOT: "-fcxx-exceptions"<br>
+// EHsc-NOT: "-fexceptions"<br>
<br>
// RUN: %clang_cl /c /EHs-c- -### -- %s 2>&1 | FileCheck -check-prefix=EHs_c_ %s<br>
// EHs_c_-NOT: "-fcxx-exceptions"<br>
@@ -16,14 +20,14 @@<br>
// EHs_EHc_-NOT: "-fcxx-exceptions"<br>
// EHs_EHc_-NOT: "-fexceptions"<br>
<br>
-// RUN: %clang_cl /c /EHs- /EHs -### -- %s 2>&1 | FileCheck -check-prefix=EHs_EHs %s<br>
+// RUN: %clang_cl /c /EHs- /EHs -fexceptions -### -- %s 2>&1 | FileCheck -check-prefix=EHs_EHs %s<br>
// EHs_EHs: "-fcxx-exceptions"<br>
// EHs_EHs: "-fexceptions"<br>
<br>
-// RUN: %clang_cl /c /EHs- /EHsa -### -- %s 2>&1 | FileCheck -check-prefix=EHs_EHa %s<br>
+// RUN: %clang_cl /c /EHs- /EHsa -fexceptions -### -- %s 2>&1 | FileCheck -check-prefix=EHs_EHa %s<br>
// EHs_EHa: "-fcxx-exceptions"<br>
// EHs_EHa: "-fexceptions"<br>
<br>
-// RUN: %clang_cl /c /EHinvalid -### -- %s 2>&1 | FileCheck -check-prefix=EHinvalid %s<br>
+// RUN: %clang_cl /c /EHinvalid -fexceptions -### -- %s 2>&1 | FileCheck -check-prefix=EHinvalid %s<br>
// EHinvalid: error: invalid value 'invalid' in '/EH'<br>
// EHinvalid-NOT: error:<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>