aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-07-17 14:14:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-07-17 14:14:24 +0200
commita1dfe8e7543f444a03849963c6fcc75ebb611de1 (patch)
tree97c32900b5068a35f0e97022396ec2944a110705 /libbuild2
parente6c9442dcc1ed481295405d13e599c22ae8d065c (diff)
Use -fexternc-nounwind by default for Clang targeting MSVC
This option implements the 'c' part in /EHsc and is not a mere optimization; see Clang bug #45021 for details.
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/cc/compile-rule.cxx32
1 files changed, 27 insertions, 5 deletions
diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx
index 29312a8..37daf76 100644
--- a/libbuild2/cc/compile-rule.cxx
+++ b/libbuild2/cc/compile-rule.cxx
@@ -5939,11 +5939,11 @@ namespace build2
append_sys_inc_options (args); // Extra system header dirs (last).
// While we want to keep the low-level build as "pure" as possible,
- // the two misguided defaults, exceptions and runtime, just have to be
- // fixed. Otherwise the default build is pretty much unusable. But we
- // also make sure that the user can easily disable our defaults: if we
- // see any relevant options explicitly specified, we take our hands
- // off.
+ // the two misguided defaults, C++ exceptions and runtime, just have
+ // to be fixed. Otherwise the default build is pretty much unusable.
+ // But we also make sure that the user can easily disable our
+ // defaults: if we see any relevant options explicitly specified, we
+ // take our hands off.
//
// For C looks like no /EH* (exceptions supported but no C++ objects
// destroyed) is a reasonable default.
@@ -6049,6 +6049,28 @@ namespace build2
{
case compiler_type::clang:
{
+ // Default to the /EHsc exceptions support for C++, similar to
+ // the the MSVC case above.
+ //
+ // Note that both vanilla clang++ and clang-cl drivers add
+ // -fexceptions and -fcxx-exceptions by default. However,
+ // clang-cl also adds -fexternc-nounwind, which implements the
+ // 'c' part in /EHsc. Note that adding this option is not a mere
+ // optimization, as we have discovered through some painful
+ // experience; see Clang bug #45021.
+ //
+ // Let's also omit this option if -f[no]-exceptions is specified
+ // explicitly.
+ //
+ if (x_lang == lang::cxx)
+ {
+ if (!find_options ({"-fexceptions", "-fno-exceptions"}, args))
+ {
+ args.push_back ("-Xclang");
+ args.push_back ("-fexternc-nounwind");
+ }
+ }
+
// Default to the multi-threaded DLL runtime (/MD), similar to
// the MSVC case above.
//