From 7d8fbeb8b9a69cee2a2f26c977ffb3f2b7b6fa92 Mon Sep 17 00:00:00 2001 From: Nicholas Ormrod Date: Fri, 31 Oct 2014 11:07:44 -0700 Subject: [PATCH] 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 --- folly/Malloc.cpp | 2 +- folly/Traits.h | 6 ++- .../symbolizer/test/SignalHandlerTest.h | 2 +- folly/test/HasMemberFnTraitsTest.cpp | 52 ++++++++++++------- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/folly/Malloc.cpp b/folly/Malloc.cpp index d1a242c2..3e510d9e 100644 --- a/folly/Malloc.cpp +++ b/folly/Malloc.cpp @@ -37,7 +37,7 @@ bool usingJEMallocSlow() { // "volatile" because gcc optimizes out the reads from *counter, because // it "knows" malloc doesn't modify global state... - volatile uint64_t* counter; + /* nolint */ volatile uint64_t* counter; size_t counterLen = sizeof(uint64_t*); if (mallctl("thread.allocatedp", static_cast(&counter), &counterLen, diff --git a/folly/Traits.h b/folly/Traits.h index 2b94df13..132e0f2b 100644 --- a/folly/Traits.h +++ b/folly/Traits.h @@ -518,7 +518,9 @@ FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr); template class classname; \ 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, volatile); \ - FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, volatile const) + FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \ + classname, func_name, /* nolint */ volatile); \ + FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \ + classname, func_name, /* nolint */ volatile const) #endif //FOLLY_BASE_TRAITS_H_ diff --git a/folly/experimental/symbolizer/test/SignalHandlerTest.h b/folly/experimental/symbolizer/test/SignalHandlerTest.h index aa646627..79bf6b2f 100644 --- a/folly/experimental/symbolizer/test/SignalHandlerTest.h +++ b/folly/experimental/symbolizer/test/SignalHandlerTest.h @@ -20,7 +20,7 @@ namespace folly { namespace symbolizer { namespace test { inline void failHard() { - *(volatile char*)42; // SIGSEGV + *(/* nolint */ volatile char*)42; // SIGSEGV } }}} // namespaces diff --git a/folly/test/HasMemberFnTraitsTest.cpp b/folly/test/HasMemberFnTraitsTest.cpp index 7944b4d4..2a9a308d 100644 --- a/folly/test/HasMemberFnTraitsTest.cpp +++ b/folly/test/HasMemberFnTraitsTest.cpp @@ -45,8 +45,8 @@ struct Bar { struct Gaz { void test(); void test() const; - void test() volatile; - void test() const volatile; + void test() /* nolint */ volatile; + void test() const /* nolint */ volatile; }; struct NoCV { @@ -58,11 +58,11 @@ struct Const { }; struct Volatile { - void test() volatile; + void test() /* nolint */ volatile; }; struct CV { - void test() const volatile; + void test() const /* nolint */ volatile; }; bool log_value(const char* what, bool result) { @@ -89,33 +89,47 @@ TEST(HasMemberFnTraits, DirectMembers) { EXPECT_TRUE(LOG_VALUE((has_test::value))); EXPECT_TRUE(LOG_VALUE((has_test::value))); - EXPECT_TRUE(LOG_VALUE((has_test::value))); - EXPECT_TRUE(LOG_VALUE((has_test::value))); - EXPECT_TRUE(LOG_VALUE((has_test::value))); + EXPECT_TRUE(LOG_VALUE((has_test::value))); + EXPECT_TRUE(LOG_VALUE(( + has_test::value))); + EXPECT_TRUE(LOG_VALUE(( + has_test::value))); EXPECT_TRUE(LOG_VALUE((has_test::value))); EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); EXPECT_FALSE(LOG_VALUE((has_test::value))); EXPECT_TRUE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); EXPECT_FALSE(LOG_VALUE((has_test::value))); EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_TRUE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); + EXPECT_TRUE(LOG_VALUE(( + has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); EXPECT_FALSE(LOG_VALUE((has_test::value))); EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_FALSE(LOG_VALUE((has_test::value))); - EXPECT_TRUE(LOG_VALUE((has_test::value))); - EXPECT_TRUE(LOG_VALUE((has_test::value))); + EXPECT_FALSE(LOG_VALUE(( + has_test::value))); + EXPECT_TRUE(LOG_VALUE(( + has_test::value))); + EXPECT_TRUE(LOG_VALUE(( + has_test::value))); } int main(int argc, char *argv[]) { -- 2.34.1