Skip to content

Commit 55e9968

Browse files
mrambacherfacebook-github-bot
authored andcommitted
No elide constructors (facebook#7798)
Summary: Added "no-elide-constructors to the ASSERT_STATUS_CHECK builds. This flag gives more errors/warnings for some of the Status checks where an inner class checks a Status and later returns it. In this case, without the elide check on, the returned status may not have been checked in the caller, thereby bypassing the checked code. Pull Request resolved: facebook#7798 Reviewed By: jay-zhuang Differential Revision: D25680451 Pulled By: pdillinger fbshipit-source-id: c3f14ed9e2a13f0a8c54d839d5fb4d1fc1e93917
1 parent 30a5ed9 commit 55e9968

33 files changed

+310
-302
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ else
190190
endif
191191

192192
ifdef ASSERT_STATUS_CHECKED
193+
# For ASC, turn off constructor elision, preventing the case where a constructor returned
194+
# by a method may pass the ASC check if the status is checked in the inner method. Forcing
195+
# the copy constructor to be invoked disables the optimization and will cause the calling method
196+
# to check the status in order to prevent an error from being raised.
197+
PLATFORM_CXXFLAGS += -fno-elide-constructors
193198
ifeq ($(filter -DROCKSDB_ASSERT_STATUS_CHECKED,$(OPT)),)
194199
OPT += -DROCKSDB_ASSERT_STATUS_CHECKED
195200
endif

db/column_family.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
335335
// was not used)
336336
auto sfm = static_cast<SstFileManagerImpl*>(db_options.sst_file_manager.get());
337337
for (size_t i = 0; i < result.cf_paths.size(); i++) {
338-
DeleteScheduler::CleanupDirectory(db_options.env, sfm, result.cf_paths[i].path);
338+
DeleteScheduler::CleanupDirectory(db_options.env, sfm,
339+
result.cf_paths[i].path)
340+
.PermitUncheckedError();
339341
}
340342
#endif
341343

db/column_family_test.cc

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ColumnFamilyTestBase : public testing::Test {
7373
db_options_.create_if_missing = true;
7474
db_options_.fail_if_options_file_error = true;
7575
db_options_.env = env_;
76-
DestroyDB(dbname_, Options(db_options_, column_family_options_));
76+
EXPECT_OK(DestroyDB(dbname_, Options(db_options_, column_family_options_)));
7777
}
7878

7979
~ColumnFamilyTestBase() override {
@@ -653,8 +653,8 @@ TEST_P(FlushEmptyCFTestWithParam, FlushEmptyCFTest) {
653653
// after flushing file B is deleted. At the same time, the min log number of
654654
// default CF is not written to manifest. Log file A still remains.
655655
// Flushed to SST file Y.
656-
Flush(1);
657-
Flush(0);
656+
ASSERT_OK(Flush(1));
657+
ASSERT_OK(Flush(0));
658658
ASSERT_OK(Put(1, "bar", "v3")); // seqID 4
659659
ASSERT_OK(Put(1, "foo", "v4")); // seqID 5
660660
ASSERT_OK(db_->FlushWAL(/*sync=*/false));
@@ -708,15 +708,15 @@ TEST_P(FlushEmptyCFTestWithParam, FlushEmptyCFTest2) {
708708
// and is set to current. Both CFs' min log number is set to file C so after
709709
// flushing file B is deleted. Log file A still remains.
710710
// Flushed to SST file Y.
711-
Flush(1);
711+
ASSERT_OK(Flush(1));
712712
ASSERT_OK(Put(0, "bar", "v2")); // seqID 4
713713
ASSERT_OK(Put(2, "bar", "v2")); // seqID 5
714714
ASSERT_OK(Put(1, "bar", "v3")); // seqID 6
715715
// Flushing all column families. This forces all CFs' min log to current. This
716716
// is written to the manifest file. Log file C is cleared.
717-
Flush(0);
718-
Flush(1);
719-
Flush(2);
717+
ASSERT_OK(Flush(0));
718+
ASSERT_OK(Flush(1));
719+
ASSERT_OK(Flush(2));
720720
// Write to log file D
721721
ASSERT_OK(Put(1, "bar", "v4")); // seqID 7
722722
ASSERT_OK(Put(1, "bar", "v5")); // seqID 8
@@ -985,7 +985,7 @@ TEST_P(ColumnFamilyTest, FlushTest) {
985985
for (int i = 0; i < 3; ++i) {
986986
uint64_t max_total_in_memory_state =
987987
MaxTotalInMemoryState();
988-
Flush(i);
988+
ASSERT_OK(Flush(i));
989989
AssertMaxTotalInMemoryState(max_total_in_memory_state);
990990
}
991991
ASSERT_OK(Put(1, "foofoo", "bar"));
@@ -1093,7 +1093,7 @@ TEST_P(ColumnFamilyTest, CrashAfterFlush) {
10931093
ASSERT_OK(batch.Put(handles_[0], Slice("foo"), Slice("bar")));
10941094
ASSERT_OK(batch.Put(handles_[1], Slice("foo"), Slice("bar")));
10951095
ASSERT_OK(db_->Write(WriteOptions(), &batch));
1096-
Flush(0);
1096+
ASSERT_OK(Flush(0));
10971097
fault_env->SetFilesystemActive(false);
10981098

10991099
std::vector<std::string> names;
@@ -1103,7 +1103,7 @@ TEST_P(ColumnFamilyTest, CrashAfterFlush) {
11031103
}
11041104
}
11051105
Close();
1106-
fault_env->DropUnsyncedFileData();
1106+
ASSERT_OK(fault_env->DropUnsyncedFileData());
11071107
fault_env->ResetState();
11081108
Open(names, {});
11091109

@@ -2236,7 +2236,7 @@ TEST_P(ColumnFamilyTest, FlushStaleColumnFamilies) {
22362236
// files for column family [one], because it's empty
22372237
AssertCountLiveFiles(4);
22382238

2239-
Flush(0);
2239+
ASSERT_OK(Flush(0));
22402240
ASSERT_EQ(0, dbfull()->TEST_total_log_size());
22412241
Close();
22422242
}
@@ -3040,7 +3040,7 @@ TEST_P(ColumnFamilyTest, IteratorCloseWALFile1) {
30403040
Iterator* it = db_->NewIterator(ReadOptions(), handles_[1]);
30413041
ASSERT_OK(it->status());
30423042
// A flush will make `it` hold the last reference of its super version.
3043-
Flush(1);
3043+
ASSERT_OK(Flush(1));
30443044

30453045
ASSERT_OK(Put(1, "fodor", "mirko"));
30463046
ASSERT_OK(Put(0, "fodor", "mirko"));
@@ -3093,7 +3093,7 @@ TEST_P(ColumnFamilyTest, IteratorCloseWALFile2) {
30933093
Iterator* it = db_->NewIterator(ro, handles_[1]);
30943094
ASSERT_OK(it->status());
30953095
// A flush will make `it` hold the last reference of its super version.
3096-
Flush(1);
3096+
ASSERT_OK(Flush(1));
30973097

30983098
ASSERT_OK(Put(1, "fodor", "mirko"));
30993099
ASSERT_OK(Put(0, "fodor", "mirko"));
@@ -3147,7 +3147,7 @@ TEST_P(ColumnFamilyTest, ForwardIteratorCloseWALFile) {
31473147
CreateColumnFamilies({"one"});
31483148
ASSERT_OK(Put(1, "fodor", "mirko"));
31493149
ASSERT_OK(Put(1, "fodar2", "mirko"));
3150-
Flush(1);
3150+
ASSERT_OK(Flush(1));
31513151

31523152
// Create an iterator holding the current super version, as well as
31533153
// the SST file just flushed.
@@ -3159,7 +3159,7 @@ TEST_P(ColumnFamilyTest, ForwardIteratorCloseWALFile) {
31593159

31603160
ASSERT_OK(Put(1, "fodor", "mirko"));
31613161
ASSERT_OK(Put(1, "fodar2", "mirko"));
3162-
Flush(1);
3162+
ASSERT_OK(Flush(1));
31633163

31643164
WaitForCompaction();
31653165

@@ -3232,9 +3232,9 @@ TEST_P(ColumnFamilyTest, LogSyncConflictFlush) {
32323232
ROCKSDB_NAMESPACE::port::Thread thread([&] { ASSERT_OK(db_->SyncWAL()); });
32333233

32343234
TEST_SYNC_POINT("ColumnFamilyTest::LogSyncConflictFlush:1");
3235-
Flush(1);
3235+
ASSERT_OK(Flush(1));
32363236
ASSERT_OK(Put(1, "foo", "bar"));
3237-
Flush(1);
3237+
ASSERT_OK(Flush(1));
32383238

32393239
TEST_SYNC_POINT("ColumnFamilyTest::LogSyncConflictFlush:2");
32403240

@@ -3256,7 +3256,7 @@ TEST_P(ColumnFamilyTest, DISABLED_LogTruncationTest) {
32563256
Build(0, 100);
32573257

32583258
// Flush the 0th column family to force a roll of the wal log
3259-
Flush(0);
3259+
ASSERT_OK(Flush(0));
32603260

32613261
// Add some more entries
32623262
Build(100, 100);
@@ -3332,14 +3332,14 @@ TEST_P(ColumnFamilyTest, DefaultCfPathsTest) {
33323332

33333333
// Fill Column family 1.
33343334
PutRandomData(1, 100, 100);
3335-
Flush(1);
3335+
ASSERT_OK(Flush(1));
33363336

33373337
ASSERT_EQ(1, GetSstFileCount(cf_opt1.cf_paths[0].path));
33383338
ASSERT_EQ(0, GetSstFileCount(dbname_));
33393339

33403340
// Fill column family 2
33413341
PutRandomData(2, 100, 100);
3342-
Flush(2);
3342+
ASSERT_OK(Flush(2));
33433343

33443344
// SST from Column family 2 should be generated in
33453345
// db_paths which is dbname_ in this case.
@@ -3358,14 +3358,14 @@ TEST_P(ColumnFamilyTest, MultipleCFPathsTest) {
33583358
Reopen({ColumnFamilyOptions(), cf_opt1, cf_opt2});
33593359

33603360
PutRandomData(1, 100, 100, true /* save */);
3361-
Flush(1);
3361+
ASSERT_OK(Flush(1));
33623362

33633363
// Check that files are generated in appropriate paths.
33643364
ASSERT_EQ(1, GetSstFileCount(cf_opt1.cf_paths[0].path));
33653365
ASSERT_EQ(0, GetSstFileCount(dbname_));
33663366

33673367
PutRandomData(2, 100, 100, true /* save */);
3368-
Flush(2);
3368+
ASSERT_OK(Flush(2));
33693369

33703370
ASSERT_EQ(1, GetSstFileCount(cf_opt2.cf_paths[0].path));
33713371
ASSERT_EQ(0, GetSstFileCount(dbname_));

db/compaction/compaction_job_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class CompactionJobTestBase : public testing::Test {
269269
&write_buffer_manager_, &write_controller_,
270270
/*block_cache_tracer=*/nullptr, /*io_tracer=*/nullptr));
271271
compaction_job_stats_.Reset();
272-
SetIdentityFile(env_, dbname_);
272+
ASSERT_OK(SetIdentityFile(env_, dbname_));
273273

274274
VersionEdit new_db;
275275
new_db.SetLogNumber(0);

db/corruption_test.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ TEST_F(CorruptionTest, FileSystemStateCorrupted) {
579579

580580
if (iter == 0) { // corrupt file size
581581
std::unique_ptr<WritableFile> file;
582-
env_->NewWritableFile(filename, &file, EnvOptions());
582+
ASSERT_OK(env_->NewWritableFile(filename, &file, EnvOptions()));
583583
ASSERT_OK(file->Append(Slice("corrupted sst")));
584584
file.reset();
585585
Status x = TryReopen(&options);
@@ -616,7 +616,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksOnFlush) {
616616
options.table_factory = mock;
617617
mock->SetCorruptionMode(mode);
618618
ASSERT_OK(DB::Open(options, dbname_, &db_));
619-
assert(db_ != nullptr);
619+
assert(db_ != nullptr); // suppress false clang-analyze report
620620
Build(10);
621621
s = db_->Flush(FlushOptions());
622622
if (mode == mock::MockTableFactory::kCorruptNone) {
@@ -642,7 +642,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksOnCompact) {
642642
std::make_shared<mock::MockTableFactory>();
643643
options.table_factory = mock;
644644
ASSERT_OK(DB::Open(options, dbname_, &db_));
645-
assert(db_ != nullptr);
645+
assert(db_ != nullptr); // suppress false clang-analyze report
646646
Build(100, 2);
647647
// ASSERT_OK(db_->Flush(FlushOptions()));
648648
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
@@ -669,7 +669,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRangeFirst) {
669669
ASSERT_OK(DestroyDB(dbname_, options));
670670
ASSERT_OK(DB::Open(options, dbname_, &db_));
671671
std::string start, end;
672-
assert(db_ != nullptr);
672+
assert(db_ != nullptr); // suppress false clang-analyze report
673673
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(),
674674
Key(3, &start), Key(7, &end)));
675675
auto snap = db_->GetSnapshot();
@@ -701,7 +701,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRange) {
701701
db_ = nullptr;
702702
ASSERT_OK(DestroyDB(dbname_, options));
703703
ASSERT_OK(DB::Open(options, dbname_, &db_));
704-
assert(db_ != nullptr);
704+
assert(db_ != nullptr); // suppress false clang-analyze report
705705
Build(10, 0, 0);
706706
std::string start, end;
707707
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(),
@@ -737,7 +737,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRangeLast) {
737737
db_ = nullptr;
738738
ASSERT_OK(DestroyDB(dbname_, options));
739739
ASSERT_OK(DB::Open(options, dbname_, &db_));
740-
assert(db_ != nullptr);
740+
assert(db_ != nullptr); // suppress false clang-analyze report
741741
std::string start, end;
742742
Build(10);
743743
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(),
@@ -775,7 +775,7 @@ TEST_F(CorruptionTest, LogCorruptionErrorsInCompactionIterator) {
775775
options.table_factory = mock;
776776

777777
ASSERT_OK(DB::Open(options, dbname_, &db_));
778-
assert(db_ != nullptr);
778+
assert(db_ != nullptr); // suppress false clang-analyze report
779779
Build(100, 2);
780780

781781
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
@@ -798,7 +798,7 @@ TEST_F(CorruptionTest, CompactionKeyOrderCheck) {
798798
std::make_shared<mock::MockTableFactory>();
799799
options.table_factory = mock;
800800
ASSERT_OK(DB::Open(options, dbname_, &db_));
801-
assert(db_ != nullptr);
801+
assert(db_ != nullptr); // suppress false clang-analyze report
802802
mock->SetCorruptionMode(mock::MockTableFactory::kCorruptReorderKey);
803803
Build(100, 2);
804804
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
@@ -884,7 +884,7 @@ TEST_F(CorruptionTest, VerifyWholeTableChecksum) {
884884
SyncPoint::GetInstance()->SetCallBack(
885885
"DBImpl::VerifySstFileChecksum:mismatch", [&](void* arg) {
886886
auto* s = reinterpret_cast<Status*>(arg);
887-
assert(s);
887+
ASSERT_NE(s, nullptr);
888888
++count;
889889
ASSERT_NOK(*s);
890890
});

0 commit comments

Comments
 (0)