Skip to content

Commit

Permalink
Enable MSVC W4 with a few exceptions. Fix warnings and bugs
Browse files Browse the repository at this point in the history
Summary: Closes facebook#3018

Differential Revision: D6079011

Pulled By: yiwu-arbug

fbshipit-source-id: 988a721e7e7617967859dba71d660fc69f4dff57
  • Loading branch information
yuslepukhin authored and facebook-github-bot committed Oct 19, 2017
1 parent b749994 commit ebab2e2
Show file tree
Hide file tree
Showing 36 changed files with 146 additions and 83 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ target_include_directories(build_version PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/util)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W3 /wd4127 /wd4800 /wd4996 /wd4351")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W4 /wd4127 /wd4800 /wd4996 /wd4351 /wd4100 /wd4204 /wd4324")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wextra -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare -Wshadow -Wno-unused-parameter -Wno-unused-variable -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -Wno-strict-aliasing")
Expand Down Expand Up @@ -560,9 +560,11 @@ set(SOURCES
$<TARGET_OBJECTS:build_version>)

if(HAVE_SSE42 AND NOT FORCE_SSE42)
if(NOT MSVC)
set_source_files_properties(
util/crc32c.cc
PROPERTIES COMPILE_FLAGS "-msse4.2")
PROPERTIES COMPILE_FLAGS "-msse4.2")
endif()
endif()

if(WIN32)
Expand Down
8 changes: 4 additions & 4 deletions db/cuckoo_table_db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ TEST_F(CuckooTableDBTest, CompactionIntoMultipleFiles) {

// Write 28 values, each 10016 B ~ 10KB
for (int idx = 0; idx < 28; ++idx) {
ASSERT_OK(Put(Key(idx), std::string(10000, 'a' + idx)));
ASSERT_OK(Put(Key(idx), std::string(10000, 'a' + char(idx))));
}
dbfull()->TEST_WaitForFlushMemTable();
ASSERT_EQ("1", FilesPerLevel());
Expand All @@ -250,7 +250,7 @@ TEST_F(CuckooTableDBTest, CompactionIntoMultipleFiles) {
true /* disallow trivial move */);
ASSERT_EQ("0,2", FilesPerLevel());
for (int idx = 0; idx < 28; ++idx) {
ASSERT_EQ(std::string(10000, 'a' + idx), Get(Key(idx)));
ASSERT_EQ(std::string(10000, 'a' + char(idx)), Get(Key(idx)));
}
}

Expand All @@ -271,14 +271,14 @@ TEST_F(CuckooTableDBTest, SameKeyInsertedInTwoDifferentFilesAndCompacted) {

// Generate one more file in level-0, and should trigger level-0 compaction
for (int idx = 0; idx < 11; ++idx) {
ASSERT_OK(Put(Key(idx), std::string(10000, 'a' + idx)));
ASSERT_OK(Put(Key(idx), std::string(10000, 'a' + char(idx))));
}
dbfull()->TEST_WaitForFlushMemTable();
dbfull()->TEST_CompactRange(0, nullptr, nullptr);

ASSERT_EQ("0,1", FilesPerLevel());
for (int idx = 0; idx < 11; ++idx) {
ASSERT_EQ(std::string(10000, 'a' + idx), Get(Key(idx)));
ASSERT_EQ(std::string(10000, 'a' + char(idx)), Get(Key(idx)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion db/db_basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST_F(DBBasicTest, ReadOnlyDB) {
Close();

auto options = CurrentOptions();
assert(options.env = env_);
assert(options.env == env_);
ASSERT_OK(ReadOnlyReopen(options));
ASSERT_EQ("v3", Get("foo"));
ASSERT_EQ("v2", Get("bar"));
Expand Down
2 changes: 0 additions & 2 deletions db/db_compaction_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ TEST_F(DBTestCompactionFilter, CompactionFilter) {
ASSERT_OK(iter->status());
while (iter->Valid()) {
ParsedInternalKey ikey(Slice(), 0, kTypeValue);
ikey.sequence = -1;
ASSERT_EQ(ParseInternalKey(iter->key(), &ikey), true);
total++;
if (ikey.sequence != 0) {
Expand Down Expand Up @@ -617,7 +616,6 @@ TEST_F(DBTestCompactionFilter, CompactionFilterContextManual) {
ASSERT_OK(iter->status());
while (iter->Valid()) {
ParsedInternalKey ikey(Slice(), 0, kTypeValue);
ikey.sequence = -1;
ASSERT_EQ(ParseInternalKey(iter->key(), &ikey), true);
total++;
if (ikey.sequence != 0) {
Expand Down
22 changes: 12 additions & 10 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ bool DBImpl::KeyMayExist(const ReadOptions& read_options,

Iterator* DBImpl::NewIterator(const ReadOptions& read_options,
ColumnFamilyHandle* column_family) {
Iterator* result = nullptr;
if (read_options.read_tier == kPersistedTier) {
return NewErrorIterator(Status::NotSupported(
"ReadTier::kPersistedData is not yet supported in iterators."));
Expand All @@ -1421,25 +1422,27 @@ Iterator* DBImpl::NewIterator(const ReadOptions& read_options,
if (read_options.managed) {
#ifdef ROCKSDB_LITE
// not supported in lite version
return NewErrorIterator(Status::InvalidArgument(
result = NewErrorIterator(Status::InvalidArgument(
"Managed Iterators not supported in RocksDBLite."));
#else
if ((read_options.tailing) || (read_options.snapshot != nullptr) ||
(is_snapshot_supported_)) {
return new ManagedIterator(this, read_options, cfd);
}
// Managed iter not supported
return NewErrorIterator(Status::InvalidArgument(
result = new ManagedIterator(this, read_options, cfd);
} else {
// Managed iter not supported
result = NewErrorIterator(Status::InvalidArgument(
"Managed Iterators not supported without snapshots."));
}
#endif
} else if (read_options.tailing) {
#ifdef ROCKSDB_LITE
// not supported in lite version
return nullptr;
result = nullptr;

#else
SuperVersion* sv = cfd->GetReferencedSuperVersion(&mutex_);
auto iter = new ForwardIterator(this, read_options, cfd, sv);
return NewDBIterator(
result = NewDBIterator(
env_, read_options, *cfd->ioptions(), cfd->user_comparator(), iter,
kMaxSequenceNumber,
sv->mutable_cf_options.max_sequential_skip_in_iterations,
Expand All @@ -1449,10 +1452,9 @@ Iterator* DBImpl::NewIterator(const ReadOptions& read_options,
auto snapshot = read_options.snapshot != nullptr
? read_options.snapshot->GetSequenceNumber()
: versions_->LastSequence();
return NewIteratorImpl(read_options, cfd, snapshot, read_callback);
result = NewIteratorImpl(read_options, cfd, snapshot, read_callback);
}
// To stop compiler from complaining
return nullptr;
return result;
}

ArenaWrappedDBIter* DBImpl::NewIteratorImpl(const ReadOptions& read_options,
Expand Down
14 changes: 7 additions & 7 deletions db/db_impl_compaction_flush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -894,15 +894,15 @@ Status DBImpl::RunManualCompaction(ColumnFamilyData* cfd, int input_level,
while (!manual.done) {
assert(HasPendingManualCompaction());
manual_conflict = false;
Compaction* compaction;
Compaction* compaction = nullptr;
if (ShouldntRunManualCompaction(&manual) || (manual.in_progress == true) ||
scheduled ||
((manual.manual_end = &manual.tmp_storage1) &&
((compaction = manual.cfd->CompactRange(
*manual.cfd->GetLatestMutableCFOptions(), manual.input_level,
manual.output_level, manual.output_path_id, manual.begin,
manual.end, &manual.manual_end, &manual_conflict)) == nullptr) &&
manual_conflict)) {
(((manual.manual_end = &manual.tmp_storage1) != nullptr) &&
((compaction = manual.cfd->CompactRange(
*manual.cfd->GetLatestMutableCFOptions(), manual.input_level,
manual.output_level, manual.output_path_id, manual.begin,
manual.end, &manual.manual_end, &manual_conflict)) == nullptr &&
manual_conflict))) {
// exclusive manual compactions should not see a conflict during
// CompactRange
assert(!exclusive || !manual_conflict);
Expand Down
4 changes: 3 additions & 1 deletion db/db_iter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ class DBIter final: public Iterator {
if (pinned_iters_mgr_.PinningEnabled()) {
pinned_iters_mgr_.ReleasePinnedData();
}
RecordTick(statistics_, NO_ITERATORS, -1);
// Compiler warning issue filed:
// https://github.com/facebook/rocksdb/issues/3013
RecordTick(statistics_, NO_ITERATORS, uint64_t(-1));
local_stats_.BumpGlobalStatistics(statistics_);
if (!arena_mode_) {
delete iter_;
Expand Down
2 changes: 1 addition & 1 deletion db/db_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ void DBTestBase::validateNumberOfEntries(int numValues, int cf) {
int seq = numValues;
while (iter->Valid()) {
ParsedInternalKey ikey;
ikey.sequence = -1;
ikey.clear();
ASSERT_EQ(ParseInternalKey(iter->key(), &ikey), true);

// checks sequence number for updates
Expand Down
10 changes: 5 additions & 5 deletions db/log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class LogTest : public ::testing::TestWithParam<int> {
}
}

void IncrementByte(int offset, int delta) {
void IncrementByte(int offset, char delta) {
dest_contents()[offset] += delta;
}

Expand Down Expand Up @@ -487,7 +487,7 @@ TEST_P(LogTest, ChecksumMismatch) {

TEST_P(LogTest, UnexpectedMiddleType) {
Write("foo");
SetByte(6, GetParam() ? kRecyclableMiddleType : kMiddleType);
SetByte(6, static_cast<char>(GetParam() ? kRecyclableMiddleType : kMiddleType));
FixChecksum(0, 3, !!GetParam());
ASSERT_EQ("EOF", Read());
ASSERT_EQ(3U, DroppedBytes());
Expand All @@ -496,7 +496,7 @@ TEST_P(LogTest, UnexpectedMiddleType) {

TEST_P(LogTest, UnexpectedLastType) {
Write("foo");
SetByte(6, GetParam() ? kRecyclableLastType : kLastType);
SetByte(6, static_cast<char>(GetParam() ? kRecyclableLastType : kLastType));
FixChecksum(0, 3, !!GetParam());
ASSERT_EQ("EOF", Read());
ASSERT_EQ(3U, DroppedBytes());
Expand All @@ -506,7 +506,7 @@ TEST_P(LogTest, UnexpectedLastType) {
TEST_P(LogTest, UnexpectedFullType) {
Write("foo");
Write("bar");
SetByte(6, GetParam() ? kRecyclableFirstType : kFirstType);
SetByte(6, static_cast<char>(GetParam() ? kRecyclableFirstType : kFirstType));
FixChecksum(0, 3, !!GetParam());
ASSERT_EQ("bar", Read());
ASSERT_EQ("EOF", Read());
Expand All @@ -517,7 +517,7 @@ TEST_P(LogTest, UnexpectedFullType) {
TEST_P(LogTest, UnexpectedFirstType) {
Write("foo");
Write(BigString("bar", 100000));
SetByte(6, GetParam() ? kRecyclableFirstType : kFirstType);
SetByte(6, static_cast<char>(GetParam() ? kRecyclableFirstType : kFirstType));
FixChecksum(0, 3, !!GetParam());
ASSERT_EQ(BigString("bar", 100000), Read());
ASSERT_EQ("EOF", Read());
Expand Down
2 changes: 1 addition & 1 deletion db/write_batch_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ TEST_F(WriteBatchTest, PrepareCommit) {
TEST_F(WriteBatchTest, DISABLED_ManyUpdates) {
// Insert key and value of 3GB and push total batch size to 12GB.
static const size_t kKeyValueSize = 4u;
static const uint32_t kNumUpdates = 3 << 30;
static const uint32_t kNumUpdates = uint32_t(3 << 30);
std::string raw(kKeyValueSize, 'A');
WriteBatch batch(kNumUpdates * (4 + kKeyValueSize * 2) + 1024u);
char c = 'A';
Expand Down
3 changes: 1 addition & 2 deletions env/env_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct Deleter {
std::unique_ptr<char, Deleter> NewAligned(const size_t size, const char ch) {
char* ptr = nullptr;
#ifdef OS_WIN
if (!(ptr = reinterpret_cast<char*>(_aligned_malloc(size, kPageSize)))) {
if (nullptr == (ptr = reinterpret_cast<char*>(_aligned_malloc(size, kPageSize)))) {
return std::unique_ptr<char, Deleter>(nullptr, Deleter(_aligned_free));
}
std::unique_ptr<char, Deleter> uptr(ptr, Deleter(_aligned_free));
Expand Down Expand Up @@ -701,7 +701,6 @@ TEST_F(EnvPosixTest, PositionedAppend) {
IoctlFriendlyTmpdir ift;
ASSERT_OK(env_->NewWritableFile(ift.name() + "/f", &writable_file, options));
const size_t kBlockSize = 4096;
const size_t kPageSize = 4096;
const size_t kDataSize = kPageSize;
// Write a page worth of 'a'
auto data_ptr = NewAligned(kDataSize, 'a');
Expand Down
7 changes: 7 additions & 0 deletions include/rocksdb/filter_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class FilterBitsBuilder {
virtual Slice Finish(std::unique_ptr<const char[]>* buf) = 0;

// Calculate num of entries fit into a space.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4702) // unreachable code
#endif
virtual int CalculateNumEntry(const uint32_t space) {
#ifndef ROCKSDB_LITE
throw std::runtime_error("CalculateNumEntry not Implemented");
Expand All @@ -54,6 +58,9 @@ class FilterBitsBuilder {
#endif
return 0;
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
};

// A class that checks if a key can be in filter
Expand Down
8 changes: 8 additions & 0 deletions include/rocksdb/utilities/env_mirror.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class EnvMirror : public EnvWrapper {
assert(as == bs);
return as;
}
#if defined(_MSC_VER)
#pragma warning(push)
// logical operation on address of string constant
#pragma warning(disable : 4130)
#endif
Status GetChildren(const std::string& dir,
std::vector<std::string>* r) override {
std::vector<std::string> ar, br;
Expand All @@ -87,6 +92,9 @@ class EnvMirror : public EnvWrapper {
*r = ar;
return as;
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
Status DeleteFile(const std::string& f) override {
Status as = a_->DeleteFile(f);
Status bs = b_->DeleteFile(f);
Expand Down
4 changes: 2 additions & 2 deletions memtable/inlineskiplist.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ InlineSkipList<Comparator>::InlineSkipList(const Comparator cmp,
Allocator* allocator,
int32_t max_height,
int32_t branching_factor)
: kMaxHeight_(max_height),
kBranching_(branching_factor),
: kMaxHeight_(static_cast<uint16_t>(max_height)),
kBranching_(static_cast<uint16_t>(branching_factor)),
kScaledInverseBranching_((Random::kMaxNext + 1) / kBranching_),
compare_(cmp),
allocator_(allocator),
Expand Down
4 changes: 2 additions & 2 deletions memtable/skiplist.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ template <typename Key, class Comparator>
SkipList<Key, Comparator>::SkipList(const Comparator cmp, Allocator* allocator,
int32_t max_height,
int32_t branching_factor)
: kMaxHeight_(max_height),
kBranching_(branching_factor),
: kMaxHeight_(static_cast<uint16_t>(max_height)),
kBranching_(static_cast<uint16_t>(branching_factor)),
kScaledInverseBranching_((Random::kMaxNext + 1) / kBranching_),
compare_(cmp),
allocator_(allocator),
Expand Down
1 change: 0 additions & 1 deletion port/win/io_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ Status WinRandomAccessImpl::ReadImpl(uint64_t offset, size_t n, Slice* result,
}

size_t left = n;
char* dest = scratch;

SSIZE_T r = PositionedReadInternal(scratch, left, offset);
if (r > 0) {
Expand Down
2 changes: 1 addition & 1 deletion table/cuckoo_table_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Status CuckooTableBuilder::MakeHashTable(std::vector<CuckooBucket>* buckets) {
buckets->resize(hash_table_size_ + cuckoo_block_size_ - 1);
uint32_t make_space_for_key_call_id = 0;
for (uint32_t vector_idx = 0; vector_idx < num_entries_; vector_idx++) {
uint64_t bucket_id;
uint64_t bucket_id = 0;
bool bucket_found = false;
autovector<uint64_t> hash_vals;
Slice user_key = GetUserKey(vector_idx);
Expand Down
16 changes: 9 additions & 7 deletions table/index_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,28 @@ IndexBuilder* IndexBuilder::CreateIndexBuilder(
const InternalKeyComparator* comparator,
const InternalKeySliceTransform* int_key_slice_transform,
const BlockBasedTableOptions& table_opt) {
IndexBuilder* result = nullptr;
switch (index_type) {
case BlockBasedTableOptions::kBinarySearch: {
return new ShortenedIndexBuilder(comparator,
result = new ShortenedIndexBuilder(comparator,
table_opt.index_block_restart_interval);
}
break;
case BlockBasedTableOptions::kHashSearch: {
return new HashIndexBuilder(comparator, int_key_slice_transform,
result = new HashIndexBuilder(comparator, int_key_slice_transform,
table_opt.index_block_restart_interval);
}
break;
case BlockBasedTableOptions::kTwoLevelIndexSearch: {
return PartitionedIndexBuilder::CreateIndexBuilder(comparator, table_opt);
result = PartitionedIndexBuilder::CreateIndexBuilder(comparator, table_opt);
}
break;
default: {
assert(!"Do not recognize the index type ");
return nullptr;
}
break;
}
// impossible.
assert(false);
return nullptr;
return result;
}

PartitionedIndexBuilder* PartitionedIndexBuilder::CreateIndexBuilder(
Expand Down
2 changes: 1 addition & 1 deletion table/plain_table_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class PlainTableFactory : public TableFactory {

const PlainTableOptions& table_options() const;

static const char kValueTypeSeqId0 = char(0xFF);
static const char kValueTypeSeqId0 = char(~0);

// Sanitizes the specified DB Options.
Status SanitizeOptions(const DBOptions& db_opts,
Expand Down
7 changes: 7 additions & 0 deletions third-party/fbson/FbsonWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
#include "FbsonDocument.h"
#include "FbsonStream.h"

// conversion' conversion from 'type1' to 'type2', possible loss of data
// Can not restore at the header end as the warnings are emitted at the point of
// template instantiation
#if defined(_MSC_VER)
#pragma warning(disable : 4244)
#endif

namespace fbson {

template <class OS_TYPE>
Expand Down
Loading

0 comments on commit ebab2e2

Please sign in to comment.