Commit fa256453 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/lang/

Summary: [Folly] Apply `clang-format` to `folly/lang/`.

Reviewed By: igorsugak

Differential Revision: D9625707

fbshipit-source-id: 345dcfbeb67981e928093b03f75125089c4210c1
parent f21a7042
......@@ -42,10 +42,12 @@ FOLLY_ALWAYS_INLINE void assume(bool cond) {
if (kIsDebug) {
detail::assume_check(cond);
} else {
#if defined(__clang__) // Must go first because Clang also defines __GNUC__.
#if defined(__clang__) // Must go first because Clang also defines __GNUC__.
__builtin_assume(cond);
#elif defined(__GNUC__)
if (!cond) { __builtin_unreachable(); }
if (!cond) {
__builtin_unreachable();
}
#elif defined(_MSC_VER)
__assume(cond);
#else
......
......@@ -236,14 +236,16 @@ struct EndianInt {
// ntohs, htons == big16
// ntohl, htonl == big32
#define FB_GEN1(fn, t, sz) \
static t fn##sz(t x) { return fn<t>(x); } \
static t fn##sz(t x) { \
return fn<t>(x); \
}
#define FB_GEN2(t, sz) \
FB_GEN1(swap, t, sz) \
FB_GEN1(big, t, sz) \
FB_GEN1(big, t, sz) \
FB_GEN1(little, t, sz)
#define FB_GEN(sz) \
#define FB_GEN(sz) \
FB_GEN2(uint##sz##_t, sz) \
FB_GEN2(int##sz##_t, sz)
......@@ -251,18 +253,21 @@ class Endian {
public:
enum class Order : uint8_t {
LITTLE,
BIG
BIG,
};
static constexpr Order order = kIsLittleEndian ? Order::LITTLE : Order::BIG;
template <class T> static T swap(T x) {
template <class T>
static T swap(T x) {
return folly::detail::EndianInt<T>::swap(x);
}
template <class T> static T big(T x) {
template <class T>
static T big(T x) {
return folly::detail::EndianInt<T>::big(x);
}
template <class T> static T little(T x) {
template <class T>
static T little(T x) {
return folly::detail::EndianInt<T>::little(x);
}
......@@ -278,19 +283,17 @@ class Endian {
#undef FB_GEN2
#undef FB_GEN1
template <class T, class Enable=void> struct Unaligned;
template <class T, class Enable = void>
struct Unaligned;
/**
* Representation of an unaligned value of a POD type.
*/
FOLLY_PACK_PUSH
template <class T>
struct Unaligned<
T,
typename std::enable_if<std::is_pod<T>::value>::type> {
Unaligned() = default; // uninitialized
/* implicit */ Unaligned(T v) : value(v) { }
struct Unaligned<T, typename std::enable_if<std::is_pod<T>::value>::type> {
Unaligned() = default; // uninitialized
/* implicit */ Unaligned(T v) : value(v) {}
T value;
} FOLLY_PACK_ATTR;
FOLLY_PACK_POP
......
......@@ -32,7 +32,7 @@ namespace cold_detail {
struct ColdClass {
FOLLY_COLD ColdClass() noexcept;
};
} // namespace cold
} // namespace cold_detail
/* using override */ using cold_detail::ColdClass;
} // namespace folly
......@@ -101,7 +101,7 @@ class rvalue_reference_wrapper {
* the wrapped reference points to a callable object. Destructive.
*/
template <class... Args>
decltype(auto) operator()(Args&&... args) &&
decltype(auto) operator()(Args&&... args) &&
noexcept(noexcept(std::declval<T>()(std::forward<Args>(args)...))) {
return static_cast<rvalue_reference_wrapper&&>(*this).get()(
std::forward<Args>(args)...);
......
......@@ -19,7 +19,8 @@
#include <folly/Conv.h>
#include <folly/FileUtil.h>
namespace folly { namespace detail {
namespace folly {
namespace detail {
namespace {
void writeStderr(const char* s, size_t len) {
......@@ -30,8 +31,12 @@ void writeStderr(const char* s) {
}
} // namespace
void assertionFailure(const char* expr, const char* msg, const char* file,
unsigned int line, const char* function) {
void assertionFailure(
const char* expr,
const char* msg,
const char* file,
unsigned int line,
const char* function) {
writeStderr("\n\nAssertion failure: ");
writeStderr(expr + 1, strlen(expr) - 2);
writeStderr("\nMessage: ");
......
......@@ -25,9 +25,13 @@
* logs to stderr and only does async-signal-safe calls.
*/
#define FOLLY_SAFE_CHECK_IMPL(expr, expr_s, msg) \
((expr) ? static_cast<void>(0) : \
::folly::detail::assertionFailure( \
FB_STRINGIZE(expr_s), (msg), __FILE__, __LINE__, __PRETTY_FUNCTION__))
((expr) ? static_cast<void>(0) \
: ::folly::detail::assertionFailure( \
FB_STRINGIZE(expr_s), \
(msg), \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__))
#define FOLLY_SAFE_CHECK(expr, msg) FOLLY_SAFE_CHECK_IMPL((expr), (expr), (msg))
/**
......@@ -38,7 +42,8 @@
#define FOLLY_SAFE_DCHECK(expr, msg) \
FOLLY_SAFE_CHECK_IMPL(!folly::kIsDebug || (expr), (expr), (msg))
namespace folly { namespace detail {
namespace folly {
namespace detail {
[[noreturn]] void assertionFailure(
const char* expr,
......
......@@ -53,13 +53,15 @@ inline int uncaught_exceptions() noexcept {
#if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS)
// __cxa_get_globals returns a __cxa_eh_globals* (defined in unwind-cxx.h).
// The offset below returns __cxa_eh_globals::uncaughtExceptions.
return *(reinterpret_cast<unsigned int*>(static_cast<char*>(
static_cast<void*>(__cxxabiv1::__cxa_get_globals())) + sizeof(void*)));
return *(reinterpret_cast<unsigned int*>(
static_cast<char*>(static_cast<void*>(__cxxabiv1::__cxa_get_globals())) +
sizeof(void*)));
#elif defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
// _getptd() returns a _tiddata* (defined in mtdll.h).
// The offset below returns _tiddata::_ProcessingThrow.
return *(reinterpret_cast<int*>(static_cast<char*>(
static_cast<void*>(_getptd())) + sizeof(void*) * 28 + 0x4 * 8));
return *(reinterpret_cast<int*>(
static_cast<char*>(static_cast<void*>(_getptd())) + sizeof(void*) * 28 +
0x4 * 8));
#elif defined(FOLLY_EXCEPTION_COUNT_USE_STD)
return std::uncaught_exceptions();
#endif
......
......@@ -43,12 +43,11 @@ namespace {
template <class INT>
void testFFS() {
EXPECT_EQ(0, findFirstSet(static_cast<INT>(0)));
size_t bits = std::numeric_limits<
typename std::make_unsigned<INT>::type>::digits;
size_t bits =
std::numeric_limits<typename std::make_unsigned<INT>::type>::digits;
for (size_t i = 0; i < bits; i++) {
INT v = (static_cast<INT>(1) << (bits - 1)) |
(static_cast<INT>(1) << i);
EXPECT_EQ(i+1, findFirstSet(v));
INT v = (static_cast<INT>(1) << (bits - 1)) | (static_cast<INT>(1) << i);
EXPECT_EQ(i + 1, findFirstSet(v));
}
}
......@@ -156,12 +155,12 @@ TEST(Bits, isPowTwo) {
EXPECT_FALSE(isPowTwo(511ul));
EXPECT_TRUE(isPowTwo(512ul));
EXPECT_FALSE(isPowTwo(513ul));
EXPECT_FALSE(isPowTwo((1ul<<31) - 1));
EXPECT_TRUE(isPowTwo(1ul<<31));
EXPECT_FALSE(isPowTwo((1ul<<31) + 1));
EXPECT_FALSE(isPowTwo((1ull<<63) - 1));
EXPECT_TRUE(isPowTwo(1ull<<63));
EXPECT_FALSE(isPowTwo((1ull<<63) + 1));
EXPECT_FALSE(isPowTwo((1ul << 31) - 1));
EXPECT_TRUE(isPowTwo(1ul << 31));
EXPECT_FALSE(isPowTwo((1ul << 31) + 1));
EXPECT_FALSE(isPowTwo((1ull << 63) - 1));
EXPECT_TRUE(isPowTwo(1ull << 63));
EXPECT_FALSE(isPowTwo((1ull << 63) + 1));
}
TEST(Bits, popcount) {
......
......@@ -23,9 +23,11 @@
using namespace folly;
// clang-format off
[[noreturn]] void fail() {
FOLLY_SAFE_CHECK(0 + 0, "hello");
}
// clang-format on
void succeed() {
FOLLY_SAFE_CHECK(1, "world");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment