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
...@@ -45,7 +45,9 @@ FOLLY_ALWAYS_INLINE void assume(bool cond) { ...@@ -45,7 +45,9 @@ FOLLY_ALWAYS_INLINE void assume(bool cond) {
#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); __builtin_assume(cond);
#elif defined(__GNUC__) #elif defined(__GNUC__)
if (!cond) { __builtin_unreachable(); } if (!cond) {
__builtin_unreachable();
}
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
__assume(cond); __assume(cond);
#else #else
......
...@@ -236,7 +236,9 @@ struct EndianInt { ...@@ -236,7 +236,9 @@ struct EndianInt {
// ntohs, htons == big16 // ntohs, htons == big16
// ntohl, htonl == big32 // ntohl, htonl == big32
#define FB_GEN1(fn, t, sz) \ #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) \ #define FB_GEN2(t, sz) \
FB_GEN1(swap, t, sz) \ FB_GEN1(swap, t, sz) \
...@@ -251,18 +253,21 @@ class Endian { ...@@ -251,18 +253,21 @@ class Endian {
public: public:
enum class Order : uint8_t { enum class Order : uint8_t {
LITTLE, LITTLE,
BIG BIG,
}; };
static constexpr Order order = kIsLittleEndian ? Order::LITTLE : Order::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); 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); 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); return folly::detail::EndianInt<T>::little(x);
} }
...@@ -278,19 +283,17 @@ class Endian { ...@@ -278,19 +283,17 @@ class Endian {
#undef FB_GEN2 #undef FB_GEN2
#undef FB_GEN1 #undef FB_GEN1
template <class T, class Enable = void>
template <class T, class Enable=void> struct Unaligned; struct Unaligned;
/** /**
* Representation of an unaligned value of a POD type. * Representation of an unaligned value of a POD type.
*/ */
FOLLY_PACK_PUSH FOLLY_PACK_PUSH
template <class T> template <class T>
struct Unaligned< struct Unaligned<T, typename std::enable_if<std::is_pod<T>::value>::type> {
T,
typename std::enable_if<std::is_pod<T>::value>::type> {
Unaligned() = default; // uninitialized Unaligned() = default; // uninitialized
/* implicit */ Unaligned(T v) : value(v) { } /* implicit */ Unaligned(T v) : value(v) {}
T value; T value;
} FOLLY_PACK_ATTR; } FOLLY_PACK_ATTR;
FOLLY_PACK_POP FOLLY_PACK_POP
......
...@@ -32,7 +32,7 @@ namespace cold_detail { ...@@ -32,7 +32,7 @@ namespace cold_detail {
struct ColdClass { struct ColdClass {
FOLLY_COLD ColdClass() noexcept; FOLLY_COLD ColdClass() noexcept;
}; };
} // namespace cold } // namespace cold_detail
/* using override */ using cold_detail::ColdClass; /* using override */ using cold_detail::ColdClass;
} // namespace folly } // namespace folly
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
#include <folly/Conv.h> #include <folly/Conv.h>
#include <folly/FileUtil.h> #include <folly/FileUtil.h>
namespace folly { namespace detail { namespace folly {
namespace detail {
namespace { namespace {
void writeStderr(const char* s, size_t len) { void writeStderr(const char* s, size_t len) {
...@@ -30,8 +31,12 @@ void writeStderr(const char* s) { ...@@ -30,8 +31,12 @@ void writeStderr(const char* s) {
} }
} // namespace } // namespace
void assertionFailure(const char* expr, const char* msg, const char* file, void assertionFailure(
unsigned int line, const char* function) { const char* expr,
const char* msg,
const char* file,
unsigned int line,
const char* function) {
writeStderr("\n\nAssertion failure: "); writeStderr("\n\nAssertion failure: ");
writeStderr(expr + 1, strlen(expr) - 2); writeStderr(expr + 1, strlen(expr) - 2);
writeStderr("\nMessage: "); writeStderr("\nMessage: ");
......
...@@ -25,9 +25,13 @@ ...@@ -25,9 +25,13 @@
* logs to stderr and only does async-signal-safe calls. * logs to stderr and only does async-signal-safe calls.
*/ */
#define FOLLY_SAFE_CHECK_IMPL(expr, expr_s, msg) \ #define FOLLY_SAFE_CHECK_IMPL(expr, expr_s, msg) \
((expr) ? static_cast<void>(0) : \ ((expr) ? static_cast<void>(0) \
::folly::detail::assertionFailure( \ : ::folly::detail::assertionFailure( \
FB_STRINGIZE(expr_s), (msg), __FILE__, __LINE__, __PRETTY_FUNCTION__)) FB_STRINGIZE(expr_s), \
(msg), \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__))
#define FOLLY_SAFE_CHECK(expr, msg) FOLLY_SAFE_CHECK_IMPL((expr), (expr), (msg)) #define FOLLY_SAFE_CHECK(expr, msg) FOLLY_SAFE_CHECK_IMPL((expr), (expr), (msg))
/** /**
...@@ -38,7 +42,8 @@ ...@@ -38,7 +42,8 @@
#define FOLLY_SAFE_DCHECK(expr, msg) \ #define FOLLY_SAFE_DCHECK(expr, msg) \
FOLLY_SAFE_CHECK_IMPL(!folly::kIsDebug || (expr), (expr), (msg)) FOLLY_SAFE_CHECK_IMPL(!folly::kIsDebug || (expr), (expr), (msg))
namespace folly { namespace detail { namespace folly {
namespace detail {
[[noreturn]] void assertionFailure( [[noreturn]] void assertionFailure(
const char* expr, const char* expr,
......
...@@ -53,13 +53,15 @@ inline int uncaught_exceptions() noexcept { ...@@ -53,13 +53,15 @@ inline int uncaught_exceptions() noexcept {
#if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) #if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS)
// __cxa_get_globals returns a __cxa_eh_globals* (defined in unwind-cxx.h). // __cxa_get_globals returns a __cxa_eh_globals* (defined in unwind-cxx.h).
// The offset below returns __cxa_eh_globals::uncaughtExceptions. // The offset below returns __cxa_eh_globals::uncaughtExceptions.
return *(reinterpret_cast<unsigned int*>(static_cast<char*>( return *(reinterpret_cast<unsigned int*>(
static_cast<void*>(__cxxabiv1::__cxa_get_globals())) + sizeof(void*))); static_cast<char*>(static_cast<void*>(__cxxabiv1::__cxa_get_globals())) +
sizeof(void*)));
#elif defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD) #elif defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
// _getptd() returns a _tiddata* (defined in mtdll.h). // _getptd() returns a _tiddata* (defined in mtdll.h).
// The offset below returns _tiddata::_ProcessingThrow. // The offset below returns _tiddata::_ProcessingThrow.
return *(reinterpret_cast<int*>(static_cast<char*>( return *(reinterpret_cast<int*>(
static_cast<void*>(_getptd())) + sizeof(void*) * 28 + 0x4 * 8)); static_cast<char*>(static_cast<void*>(_getptd())) + sizeof(void*) * 28 +
0x4 * 8));
#elif defined(FOLLY_EXCEPTION_COUNT_USE_STD) #elif defined(FOLLY_EXCEPTION_COUNT_USE_STD)
return std::uncaught_exceptions(); return std::uncaught_exceptions();
#endif #endif
......
...@@ -43,12 +43,11 @@ namespace { ...@@ -43,12 +43,11 @@ namespace {
template <class INT> template <class INT>
void testFFS() { void testFFS() {
EXPECT_EQ(0, findFirstSet(static_cast<INT>(0))); EXPECT_EQ(0, findFirstSet(static_cast<INT>(0)));
size_t bits = std::numeric_limits< size_t bits =
typename std::make_unsigned<INT>::type>::digits; std::numeric_limits<typename std::make_unsigned<INT>::type>::digits;
for (size_t i = 0; i < bits; i++) { for (size_t i = 0; i < bits; i++) {
INT v = (static_cast<INT>(1) << (bits - 1)) | INT v = (static_cast<INT>(1) << (bits - 1)) | (static_cast<INT>(1) << i);
(static_cast<INT>(1) << i); EXPECT_EQ(i + 1, findFirstSet(v));
EXPECT_EQ(i+1, findFirstSet(v));
} }
} }
...@@ -156,12 +155,12 @@ TEST(Bits, isPowTwo) { ...@@ -156,12 +155,12 @@ TEST(Bits, isPowTwo) {
EXPECT_FALSE(isPowTwo(511ul)); EXPECT_FALSE(isPowTwo(511ul));
EXPECT_TRUE(isPowTwo(512ul)); EXPECT_TRUE(isPowTwo(512ul));
EXPECT_FALSE(isPowTwo(513ul)); EXPECT_FALSE(isPowTwo(513ul));
EXPECT_FALSE(isPowTwo((1ul<<31) - 1)); EXPECT_FALSE(isPowTwo((1ul << 31) - 1));
EXPECT_TRUE(isPowTwo(1ul<<31)); EXPECT_TRUE(isPowTwo(1ul << 31));
EXPECT_FALSE(isPowTwo((1ul<<31) + 1)); EXPECT_FALSE(isPowTwo((1ul << 31) + 1));
EXPECT_FALSE(isPowTwo((1ull<<63) - 1)); EXPECT_FALSE(isPowTwo((1ull << 63) - 1));
EXPECT_TRUE(isPowTwo(1ull<<63)); EXPECT_TRUE(isPowTwo(1ull << 63));
EXPECT_FALSE(isPowTwo((1ull<<63) + 1)); EXPECT_FALSE(isPowTwo((1ull << 63) + 1));
} }
TEST(Bits, popcount) { TEST(Bits, popcount) {
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
using namespace folly; using namespace folly;
// clang-format off
[[noreturn]] void fail() { [[noreturn]] void fail() {
FOLLY_SAFE_CHECK(0 + 0, "hello"); FOLLY_SAFE_CHECK(0 + 0, "hello");
} }
// clang-format on
void succeed() { void succeed() {
FOLLY_SAFE_CHECK(1, "world"); 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