From 9cc25190e1ba6fc66bbd0d47caaf043d75839b6f Mon Sep 17 00:00:00 2001 From: sdong Date: Wed, 24 Jun 2020 16:20:55 -0700 Subject: [PATCH] Test CircleCI with CLANG-10 (#7025) Summary: It's useful to build RocksDB using a more recent clang version in CI. Add a CircleCI build and fix some issues with it. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7025 Test Plan: See all tests pass. Reviewed By: pdillinger Differential Revision: D22215700 fbshipit-source-id: 914a729c2cd3f3ac4a627cc0ac58d4691dca2168 --- .circleci/config.yml | 15 +++++++++++++++ db/db_iter_stress_test.cc | 11 +++++++---- db/db_options_test.cc | 4 ++-- env/env_test.cc | 4 ++-- options/options_helper.cc | 2 +- table/table_test.cc | 10 +++++----- tools/ldb_cmd_test.cc | 2 +- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a6a7f879d..a2408facd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,6 +57,18 @@ jobs: - run: sudo apt-get install -y clang - run: CC=clang CXX=clang++ USE_CLANG=1 PORTABLE=1 make all -j32 + build-linux-clang10-no-test: + machine: + image: ubuntu-1604:201903-01 + resource_class: 2xlarge + steps: + - checkout # check out the code in the project directory + - run: sudo sh -c 'echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main" >> /etc/apt/sources.list' + - run: sudo sh -c 'echo "deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main" >> /etc/apt/sources.list' + - run: sudo apt-get update -y + - run: sudo apt-get install -y clang-10 + - run: CC=clang-10 CXX=clang++-10 ROCKSDB_DISABLE_ALIGNED_NEW=1 USE_CLANG=1 make all -j32 # aligned new doesn't work for reason we haven't figured out + build-linux-cmake: machine: image: ubuntu-1604:201903-01 @@ -125,6 +137,9 @@ workflows: build-linux-clang-no-test: jobs: - build-linux-clang-no-test + build-linux-clang10-no-test: + jobs: + - build-linux-clang10-no-test build-linux-cmake: jobs: - build-linux-cmake diff --git a/db/db_iter_stress_test.cc b/db/db_iter_stress_test.cc index 57cd9866e..484bb0b45 100644 --- a/db/db_iter_stress_test.cc +++ b/db/db_iter_stress_test.cc @@ -97,7 +97,8 @@ struct StressTestIterator : public InternalIterator { bool MaybeFail() { if (rnd->Next() >= - std::numeric_limits::max() * error_probability) { + static_cast(std::numeric_limits::max()) * + error_probability) { return false; } if (rnd->Next() % 2) { @@ -114,7 +115,8 @@ struct StressTestIterator : public InternalIterator { void MaybeMutate() { if (rnd->Next() >= - std::numeric_limits::max() * mutation_probability) { + static_cast(std::numeric_limits::max()) * + mutation_probability) { return; } do { @@ -126,8 +128,9 @@ struct StressTestIterator : public InternalIterator { if (data->hidden.empty()) { hide_probability = 1; } - bool do_hide = - rnd->Next() < std::numeric_limits::max() * hide_probability; + bool do_hide = rnd->Next() < + static_cast(std::numeric_limits::max()) * + hide_probability; if (do_hide) { // Hide a random entry. size_t idx = rnd->Next() % data->entries.size(); diff --git a/db/db_options_test.cc b/db/db_options_test.cc index cc9182461..8cc09ec54 100644 --- a/db/db_options_test.cc +++ b/db/db_options_test.cc @@ -39,7 +39,7 @@ class DBOptionsTest : public DBTestBase { std::unordered_map options_map; StringToMap(options_str, &options_map); std::unordered_map mutable_map; - for (const auto opt : db_options_type_info) { + for (const auto& opt : db_options_type_info) { if (opt.second.IsMutable() && opt.second.ShouldSerialize()) { mutable_map[opt.first] = options_map[opt.first]; } @@ -57,7 +57,7 @@ class DBOptionsTest : public DBTestBase { std::unordered_map options_map; StringToMap(options_str, &options_map); std::unordered_map mutable_map; - for (const auto opt : cf_options_type_info) { + for (const auto& opt : cf_options_type_info) { if (opt.second.IsMutable() && opt.second.ShouldSerialize()) { mutable_map[opt.first] = options_map[opt.first]; } diff --git a/env/env_test.cc b/env/env_test.cc index d62f69192..e3bc7141b 100644 --- a/env/env_test.cc +++ b/env/env_test.cc @@ -1120,7 +1120,7 @@ TEST_P(EnvPosixTestWithParam, RandomAccessUniqueIDConcurrent) { // Collect and check whether the IDs are unique. std::unordered_set ids; - for (const std::string fname : fnames) { + for (const std::string& fname : fnames) { std::unique_ptr file; std::string unique_id; ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions)); @@ -1134,7 +1134,7 @@ TEST_P(EnvPosixTestWithParam, RandomAccessUniqueIDConcurrent) { } // Delete the files - for (const std::string fname : fnames) { + for (const std::string& fname : fnames) { ASSERT_OK(env_->DeleteFile(fname)); } diff --git a/options/options_helper.cc b/options/options_helper.cc index b01d389a4..396a82978 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -656,7 +656,7 @@ Status GetStringFromStruct( std::string* opt_string) { assert(opt_string); opt_string->clear(); - for (const auto iter : type_info) { + for (const auto& iter : type_info) { const auto& opt_info = iter.second; // If the option is no longer used in rocksdb and marked as deprecated, // we skip it in the serialization. diff --git a/table/table_test.cc b/table/table_test.cc index 589b48788..5899ae945 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -228,7 +228,7 @@ class BlockConstructor: public Constructor { block_ = nullptr; BlockBuilder builder(table_options.block_restart_interval); - for (const auto kv : kv_map) { + for (const auto& kv : kv_map) { builder.Add(kv.first, kv.second); } // Open the block @@ -352,7 +352,7 @@ class TableConstructor: public Constructor { TablePropertiesCollectorFactory::Context::kUnknownColumnFamily, file_writer_.get())); - for (const auto kv : kv_map) { + for (const auto& kv : kv_map) { if (convert_to_internal_key_) { ParsedInternalKey ikey(kv.first, kMaxSequenceNumber, kTypeValue); std::string encoded; @@ -487,7 +487,7 @@ class MemTableConstructor: public Constructor { kMaxSequenceNumber, 0 /* column_family_id */); memtable_->Ref(); int seq = 1; - for (const auto kv : kv_map) { + for (const auto& kv : kv_map) { memtable_->Add(seq, kTypeValue, kv.first, kv.second); seq++; } @@ -548,7 +548,7 @@ class DBConstructor: public Constructor { delete db_; db_ = nullptr; NewDB(); - for (const auto kv : kv_map) { + for (const auto& kv : kv_map) { WriteBatch batch; batch.Put(kv.first, kv.second); EXPECT_TRUE(db_->Write(WriteOptions(), &batch).ok()); @@ -1226,7 +1226,7 @@ class FileChecksumTestHelper { } Status WriteKVAndFlushTable() { - for (const auto kv : kv_map_) { + for (const auto& kv : kv_map_) { if (convert_to_internal_key_) { ParsedInternalKey ikey(kv.first, kMaxSequenceNumber, kTypeValue); std::string encoded; diff --git a/tools/ldb_cmd_test.cc b/tools/ldb_cmd_test.cc index e485ab551..69f7f8273 100644 --- a/tools/ldb_cmd_test.cc +++ b/tools/ldb_cmd_test.cc @@ -76,7 +76,7 @@ TEST_F(LdbCmdTest, HexToStringBadInputs) { const vector badInputs = { "0xZZ", "123", "0xx5", "0x111G", "0x123", "Ox12", "0xT", "0x1Q1", }; - for (const auto badInput : badInputs) { + for (const auto& badInput : badInputs) { try { ROCKSDB_NAMESPACE::LDBCommand::HexToString(badInput); std::cerr << "Should fail on bad hex value: " << badInput << "\n";