Commit 7d8fbeb8 authored by Nicholas Ormrod's avatar Nicholas Ormrod Committed by Pavlo Kushnir

volatile override

Summary:
Some uses of volatile are legit. Add a hidden override.

Test Plan: run unit tests

Run flint against folly/Malloc.cpp, see no more volatile warning.

Reviewed By: andrei.alexandrescu@fb.com

Subscribers: sdwilsh, louisk, njormrod, folly-diffs@

FB internal diff: D1644493

Tasks: 5486739

Signature: t1:1644493:1414715317:491d0f631d8152a5b7ec66237e00c404530ab590
parent f7e3adf5
...@@ -37,7 +37,7 @@ bool usingJEMallocSlow() { ...@@ -37,7 +37,7 @@ bool usingJEMallocSlow() {
// "volatile" because gcc optimizes out the reads from *counter, because // "volatile" because gcc optimizes out the reads from *counter, because
// it "knows" malloc doesn't modify global state... // it "knows" malloc doesn't modify global state...
volatile uint64_t* counter; /* nolint */ volatile uint64_t* counter;
size_t counterLen = sizeof(uint64_t*); size_t counterLen = sizeof(uint64_t*);
if (mallctl("thread.allocatedp", static_cast<void*>(&counter), &counterLen, if (mallctl("thread.allocatedp", static_cast<void*>(&counter), &counterLen,
......
...@@ -518,7 +518,9 @@ FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr); ...@@ -518,7 +518,9 @@ FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr);
template <typename, typename> class classname; \ template <typename, typename> class classname; \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, ); \ FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, ); \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, const); \ FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, const); \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, volatile); \ FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, volatile const) classname, func_name, /* nolint */ volatile); \
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
classname, func_name, /* nolint */ volatile const)
#endif //FOLLY_BASE_TRAITS_H_ #endif //FOLLY_BASE_TRAITS_H_
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
namespace folly { namespace symbolizer { namespace test { namespace folly { namespace symbolizer { namespace test {
inline void failHard() { inline void failHard() {
*(volatile char*)42; // SIGSEGV *(/* nolint */ volatile char*)42; // SIGSEGV
} }
}}} // namespaces }}} // namespaces
......
...@@ -45,8 +45,8 @@ struct Bar { ...@@ -45,8 +45,8 @@ struct Bar {
struct Gaz { struct Gaz {
void test(); void test();
void test() const; void test() const;
void test() volatile; void test() /* nolint */ volatile;
void test() const volatile; void test() const /* nolint */ volatile;
}; };
struct NoCV { struct NoCV {
...@@ -58,11 +58,11 @@ struct Const { ...@@ -58,11 +58,11 @@ struct Const {
}; };
struct Volatile { struct Volatile {
void test() volatile; void test() /* nolint */ volatile;
}; };
struct CV { struct CV {
void test() const volatile; void test() const /* nolint */ volatile;
}; };
bool log_value(const char* what, bool result) { bool log_value(const char* what, bool result) {
...@@ -89,33 +89,47 @@ TEST(HasMemberFnTraits, DirectMembers) { ...@@ -89,33 +89,47 @@ TEST(HasMemberFnTraits, DirectMembers) {
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void()>::value))); EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void()>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const>::value))); EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() volatile>::value))); EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() /* nolint */ volatile>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const volatile>::value))); EXPECT_TRUE(LOG_VALUE((
EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() volatile const>::value))); has_test<Gaz, void() const /* nolint */ volatile>::value)));
EXPECT_TRUE(LOG_VALUE((
has_test<Gaz, void() /* nolint */ volatile const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<NoCV, void()>::value))); EXPECT_TRUE(LOG_VALUE((has_test<NoCV, void()>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const>::value))); EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() volatile>::value))); EXPECT_FALSE(LOG_VALUE((
EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const volatile>::value))); has_test<NoCV, void() /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() volatile const>::value))); EXPECT_FALSE(LOG_VALUE((
has_test<NoCV, void() const /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE((
has_test<NoCV, void() /* nolint */ volatile const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Const, void()>::value))); EXPECT_FALSE(LOG_VALUE((has_test<Const, void()>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Const, void() const>::value))); EXPECT_TRUE(LOG_VALUE((has_test<Const, void() const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Const, void() volatile>::value))); EXPECT_FALSE(LOG_VALUE((
EXPECT_FALSE(LOG_VALUE((has_test<Const, void() const volatile>::value))); has_test<Const, void() /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Const, void() volatile const>::value))); EXPECT_FALSE(LOG_VALUE((
has_test<Const, void() const /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE((
has_test<Const, void() /* nolint */ volatile const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void()>::value))); EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void()>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const>::value))); EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<Volatile, void() volatile>::value))); EXPECT_TRUE(LOG_VALUE((
EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const volatile>::value))); has_test<Volatile, void() /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() volatile const>::value))); EXPECT_FALSE(LOG_VALUE((
has_test<Volatile, void() const /* nolint */ volatile>::value)));
EXPECT_FALSE(LOG_VALUE((
has_test<Volatile, void() /* nolint */ volatile const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<CV, void()>::value))); EXPECT_FALSE(LOG_VALUE((has_test<CV, void()>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<CV, void() const>::value))); EXPECT_FALSE(LOG_VALUE((has_test<CV, void() const>::value)));
EXPECT_FALSE(LOG_VALUE((has_test<CV, void() volatile>::value))); EXPECT_FALSE(LOG_VALUE((
EXPECT_TRUE(LOG_VALUE((has_test<CV, void() const volatile>::value))); has_test<CV, void() /* nolint */ volatile>::value)));
EXPECT_TRUE(LOG_VALUE((has_test<CV, void() volatile const>::value))); EXPECT_TRUE(LOG_VALUE((
has_test<CV, void() const /* nolint */ volatile>::value)));
EXPECT_TRUE(LOG_VALUE((
has_test<CV, void() /* nolint */ volatile const>::value)));
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
......
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