summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2023-05-16 15:13:54 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-17 20:35:57 +0000
commitd2a24d73cb763b1564c8907bf293c467aabb5b6c (patch)
tree0e926ce7717864a2b4a2b8f56e06b562bf02780b
parente90dcb18de438b6b6ab02b2c921463fd35b866cb (diff)
downloadmongo-d2a24d73cb763b1564c8907bf293c467aabb5b6c.tar.gz
SERVER-77193 Centralize the macro definition of __has_feature into one place
-rw-r--r--src/mongo/bson/bsonelement.cpp5
-rw-r--r--src/mongo/client/connpool.cpp4
-rw-r--r--src/mongo/db/concurrency/lock_state.cpp3
-rw-r--r--src/mongo/db/mongod_main.cpp4
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp4
-rw-r--r--src/mongo/platform/compiler.h6
-rw-r--r--src/mongo/s/mongos_main.cpp4
-rw-r--r--src/mongo/scripting/mozjs/implscope.cpp5
-rw-r--r--src/mongo/scripting/mozjs/jscustomallocator.cpp4
-rw-r--r--src/mongo/stdx/sigaltstack_location_test.cpp6
-rw-r--r--src/mongo/transport/service_entry_point_impl.cpp5
-rw-r--r--src/mongo/transport/service_executor_utils.cpp5
-rw-r--r--src/mongo/unittest/death_test.cpp4
-rw-r--r--src/mongo/util/future_test_utils.h4
-rw-r--r--src/mongo/util/quick_exit.cpp4
-rw-r--r--src/mongo/util/signal_handlers_synchronous_test.cpp4
-rw-r--r--src/mongo/util/stacktrace_posix.cpp4
-rw-r--r--src/mongo/watchdog/watchdog_test.cpp2
18 files changed, 10 insertions, 67 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 1d62d0c3491..25921e0b176 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -54,11 +54,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
-
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
namespace mongo {
using std::dec;
diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp
index 1442275d9f0..a8af3da9efa 100644
--- a/src/mongo/client/connpool.cpp
+++ b/src/mongo/client/connpool.cpp
@@ -51,10 +51,6 @@
#include "mongo/util/fail_point.h"
#include "mongo/util/net/socket_exception.h"
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
#if __has_feature(address_sanitizer)
#include <sanitizer/lsan_interface.h>
#endif
diff --git a/src/mongo/db/concurrency/lock_state.cpp b/src/mongo/db/concurrency/lock_state.cpp
index 4995437c533..e53a2e955b7 100644
--- a/src/mongo/db/concurrency/lock_state.cpp
+++ b/src/mongo/db/concurrency/lock_state.cpp
@@ -54,7 +54,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
-
namespace mongo {
MONGO_FAIL_POINT_DEFINE(failNonIntentLocksIfWaitNeeded);
@@ -65,7 +64,7 @@ namespace {
// Ignore data races in certain functions when running with TSAN. For performance reasons,
// diagnostic commands are expected to race with concurrent lock acquisitions while gathering
// statistics.
-#if defined(__has_feature) && __has_feature(thread_sanitizer)
+#if __has_feature(thread_sanitizer)
#define MONGO_TSAN_IGNORE __attribute__((no_sanitize("thread")))
#else
#define MONGO_TSAN_IGNORE
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp
index 589ad967da8..8a8e057a8b4 100644
--- a/src/mongo/db/mongod_main.cpp
+++ b/src/mongo/db/mongod_main.cpp
@@ -1333,10 +1333,6 @@ MONGO_INITIALIZER_GENERAL(setSSLManagerType, (), ("SSLManager"))
}
#endif
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
// NOTE: This function may be called at any time after registerShutdownTask is called below. It
// must not depend on the prior execution of mongo initializers or the existence of threads.
void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index 2fefa77da8a..b9739ac8d3a 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -129,10 +129,6 @@ MONGO_FAIL_POINT_DEFINE(WTDisableFastShutDown);
const std::string kPinOldestTimestampAtStartupName = "_wt_startup";
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
#if __has_feature(address_sanitizer)
constexpr bool kAddressSanitizerEnabled = true;
#else
diff --git a/src/mongo/platform/compiler.h b/src/mongo/platform/compiler.h
index ba74feb862d..faf1c72ec1e 100644
--- a/src/mongo/platform/compiler.h
+++ b/src/mongo/platform/compiler.h
@@ -195,3 +195,9 @@
#else
#error "Unsupported compiler family"
#endif
+
+// Define clang's has_feature macro for other compilers
+// See https://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
+#if !defined(__has_feature)
+#define __has_feature(x) 0
+#endif
diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp
index 8f0a4f7758b..cb4bd48295a 100644
--- a/src/mongo/s/mongos_main.cpp
+++ b/src/mongo/s/mongos_main.cpp
@@ -132,10 +132,6 @@ namespace mongo {
using logv2::LogComponent;
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
// Failpoint for disabling replicaSetChangeConfigServerUpdateHook calls on signaled mongos.
MONGO_FAIL_POINT_DEFINE(failReplicaSetChangeConfigServerUpdateHook);
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp
index 243a1273212..28800bc5566 100644
--- a/src/mongo/scripting/mozjs/implscope.cpp
+++ b/src/mongo/scripting/mozjs/implscope.cpp
@@ -67,11 +67,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kQuery
-
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
namespace mongo {
// Generated symbols for JS files
diff --git a/src/mongo/scripting/mozjs/jscustomallocator.cpp b/src/mongo/scripting/mozjs/jscustomallocator.cpp
index 28afb60fa88..b3f4dd4c491 100644
--- a/src/mongo/scripting/mozjs/jscustomallocator.cpp
+++ b/src/mongo/scripting/mozjs/jscustomallocator.cpp
@@ -49,10 +49,6 @@
#define MONGO_NO_MALLOC_USABLE_SIZE
#endif
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
/**
* This shim interface (which controls dynamic allocation within SpiderMonkey),
* consciously uses std::malloc and friends over mongoMalloc. It does this
diff --git a/src/mongo/stdx/sigaltstack_location_test.cpp b/src/mongo/stdx/sigaltstack_location_test.cpp
index 6c57146721f..daf1a47a946 100644
--- a/src/mongo/stdx/sigaltstack_location_test.cpp
+++ b/src/mongo/stdx/sigaltstack_location_test.cpp
@@ -44,6 +44,8 @@
#include <unistd.h>
#endif
+#include "mongo/platform/compiler.h"
+
#if !MONGO_HAS_SIGALTSTACK
int main() {
@@ -53,10 +55,6 @@ int main() {
#else // MONGO_HAS_SIGALTSTACK
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
namespace mongo::stdx {
namespace {
diff --git a/src/mongo/transport/service_entry_point_impl.cpp b/src/mongo/transport/service_entry_point_impl.cpp
index 24f2a7c04ed..c0f6381a8d5 100644
--- a/src/mongo/transport/service_entry_point_impl.cpp
+++ b/src/mongo/transport/service_entry_point_impl.cpp
@@ -70,11 +70,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kNetwork
-
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
namespace mongo {
using namespace fmt::literals;
diff --git a/src/mongo/transport/service_executor_utils.cpp b/src/mongo/transport/service_executor_utils.cpp
index 317e4261598..ec2966aa92d 100644
--- a/src/mongo/transport/service_executor_utils.cpp
+++ b/src/mongo/transport/service_executor_utils.cpp
@@ -48,11 +48,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kDefault
-
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
namespace mongo::transport {
namespace {
diff --git a/src/mongo/unittest/death_test.cpp b/src/mongo/unittest/death_test.cpp
index 7a6006a0b8c..7a166d0e777 100644
--- a/src/mongo/unittest/death_test.cpp
+++ b/src/mongo/unittest/death_test.cpp
@@ -52,7 +52,7 @@
#include <TargetConditionals.h>
#endif
-#if defined(__has_feature) && __has_feature(thread_sanitizer)
+#if __has_feature(thread_sanitizer)
#include <sanitizer/common_interface_defs.h>
#endif
@@ -67,7 +67,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest
-#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
#define TSAN_ENABLED_
#endif
@@ -77,7 +76,6 @@
#if __has_feature(memory_sanitizer)
#define MSAN_ENABLED_
#endif
-#endif // __has_feature
namespace mongo {
namespace unittest {
diff --git a/src/mongo/util/future_test_utils.h b/src/mongo/util/future_test_utils.h
index 6608b254193..14101383463 100644
--- a/src/mongo/util/future_test_utils.h
+++ b/src/mongo/util/future_test_utils.h
@@ -36,10 +36,6 @@
#include "mongo/unittest/unittest.h"
#include "mongo/util/executor_test_util.h"
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
/** Workaround for bug in MSVC 2022's lambda processor. See SERVER-62480. */
#ifdef _MSC_VER
#define FTU_LAMBDA_R(...) ->__VA_ARGS__
diff --git a/src/mongo/util/quick_exit.cpp b/src/mongo/util/quick_exit.cpp
index 0e89fcfcc3f..58f5b408397 100644
--- a/src/mongo/util/quick_exit.cpp
+++ b/src/mongo/util/quick_exit.cpp
@@ -45,10 +45,6 @@
// NOTE: Header only dependencies are OK in this library.
#include "mongo/stdx/mutex.h" // IWYU pragma: keep
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
#if !defined(__has_include)
#define __has_include(x) 0
#endif
diff --git a/src/mongo/util/signal_handlers_synchronous_test.cpp b/src/mongo/util/signal_handlers_synchronous_test.cpp
index 39629adebbf..6a9f0929035 100644
--- a/src/mongo/util/signal_handlers_synchronous_test.cpp
+++ b/src/mongo/util/signal_handlers_synchronous_test.cpp
@@ -64,10 +64,6 @@ FATAL_SIGNAL(SIGQUIT)
FATAL_SIGNAL(SIGILL)
FATAL_SIGNAL(SIGABRT)
-#if not defined(__has_feature)
-#define __has_feature(X) 0
-#endif
-
#if !__has_feature(address_sanitizer)
// These signals trip the leak sanitizer
FATAL_SIGNAL(SIGSEGV)
diff --git a/src/mongo/util/stacktrace_posix.cpp b/src/mongo/util/stacktrace_posix.cpp
index 154f5f905c5..293df356747 100644
--- a/src/mongo/util/stacktrace_posix.cpp
+++ b/src/mongo/util/stacktrace_posix.cpp
@@ -57,10 +57,6 @@
#if defined(MONGO_CONFIG_USE_LIBUNWIND)
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif
-
#if __has_feature(thread_sanitizer)
// TODO: SERVER-48622 (and see also https://github.com/google/sanitizers/issues/943)
#error "Cannot currently use libunwind with -fsanitize=thread"
diff --git a/src/mongo/watchdog/watchdog_test.cpp b/src/mongo/watchdog/watchdog_test.cpp
index aa096f3dd09..090731c9cd6 100644
--- a/src/mongo/watchdog/watchdog_test.cpp
+++ b/src/mongo/watchdog/watchdog_test.cpp
@@ -214,11 +214,9 @@ public:
}
// Ignore data races in this function when running with TSAN, races are acceptable here
-#if defined(__has_feature)
#if __has_feature(thread_sanitizer)
__attribute__((no_sanitize("thread")))
#endif
-#endif
void
setSignalOnCount(int c) {
_wait = c;