Skip to content

Commit

Permalink
Fix '-Wbitwise-instead-of-logical' in fbpcf/engine/test/SecretShareEn…
Browse files Browse the repository at this point in the history
…gineTest.cpp

Summary:
LLVM-15 requires that we differentiate between `&&` and `&` as well as `||` and `|`. Logical operations are done with `&&` and `||` and bitwise operations are done with `&` and `|`. Confusing the two makes code harder to read and may lead to subtle bugs.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: meyering

Differential Revision: D42374522

fbshipit-source-id: 12e63bd9566e5c50b852e2feb7a93d321040d924
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 6, 2023
1 parent 334e4ac commit 7c0d5eb
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions fbpcf/engine/test/SecretShareEngineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,16 +1009,16 @@ TEST_P(NonFreeMultAndANDTestFixture, TestMultAndAND) {
ASSERT_EQ(andResult.size(), 2 * size);
for (int i = 0; i < size / 2; i++) {
EXPECT_EQ(
andResult[i], boolInputs[i].first & boolInputs[i + size / 2].first);
andResult[i], boolInputs[i].first && boolInputs[i + size / 2].first);
EXPECT_EQ(
andResult[i + size / 2],
boolInputs[i].first & boolInputs[i + size / 2].first);
boolInputs[i].first && boolInputs[i + size / 2].first);
EXPECT_EQ(
andResult[i + size],
boolInputs[i].first & boolInputs[i + size / 2].first);
boolInputs[i].first && boolInputs[i + size / 2].first);
EXPECT_EQ(
andResult[i + size / 2 + size],
boolInputs[i].first & boolInputs[i + size / 2].first);
boolInputs[i].first && boolInputs[i + size / 2].first);
}

int composite15EndIndex = size / 16;
Expand All @@ -1032,21 +1032,21 @@ TEST_P(NonFreeMultAndANDTestFixture, TestMultAndAND) {
for (int j = 0; j < 15; j++) {
EXPECT_EQ(
compositeAndResult[i][j],
boolInputs[i].first & boolInputs[size / 16 + 15 * i + j].first);
boolInputs[i].first && boolInputs[size / 16 + 15 * i + j].first);
EXPECT_EQ(
compositeAndResult[j + composite3EndIndex][i],
boolInputs[i].first & boolInputs[size / 16 + 15 * i + j].first);
boolInputs[i].first && boolInputs[size / 16 + 15 * i + j].first);
}
}

for (int i = 0; i < size / 8; i++) {
for (int j = 0; j < 7; j++) {
EXPECT_EQ(
compositeAndResult[i + composite15EndIndex][j],
boolInputs[i].first & boolInputs[size / 8 + 7 * i + j].first);
boolInputs[i].first && boolInputs[size / 8 + 7 * i + j].first);
EXPECT_EQ(
compositeAndResult[j + batchComposite15EndIndex][i],
boolInputs[i].first & boolInputs[size / 8 + 7 * i + j].first);
boolInputs[i].first && boolInputs[size / 8 + 7 * i + j].first);
}
}

Expand All @@ -1055,10 +1055,10 @@ TEST_P(NonFreeMultAndANDTestFixture, TestMultAndAND) {
for (int j = 0; j < 3; j++) {
EXPECT_EQ(
compositeAndResult[i + composite7EndIndex][j],
boolInputs[i].first & boolInputs[size / 4 + 3 * i + j].first);
boolInputs[i].first && boolInputs[size / 4 + 3 * i + j].first);
EXPECT_EQ(
compositeAndResult[j + batchComposite7EndIndex][i],
boolInputs[i].first & boolInputs[size / 4 + 3 * i + j].first);
boolInputs[i].first && boolInputs[size / 4 + 3 * i + j].first);
}
}

Expand Down Expand Up @@ -1169,14 +1169,14 @@ TEST_P(NonFreeAndTestFixture, TestAnd) {
auto compositeAndResult = std::get<1>(rst);
ASSERT_EQ(andResult.size(), 2 * size);
for (int i = 0; i < size / 2; i++) {
EXPECT_EQ(andResult[i], inputs[i].first & inputs[i + size / 2].first);
EXPECT_EQ(andResult[i], inputs[i].first && inputs[i + size / 2].first);
EXPECT_EQ(
andResult[i + size / 2], inputs[i].first & inputs[i + size / 2].first);
andResult[i + size / 2], inputs[i].first && inputs[i + size / 2].first);
EXPECT_EQ(
andResult[i + size], inputs[i].first & inputs[i + size / 2].first);
andResult[i + size], inputs[i].first && inputs[i + size / 2].first);
EXPECT_EQ(
andResult[i + size / 2 + size],
inputs[i].first & inputs[i + size / 2].first);
inputs[i].first && inputs[i + size / 2].first);
}

// Ordering of composite results
Expand All @@ -1198,21 +1198,21 @@ TEST_P(NonFreeAndTestFixture, TestAnd) {
for (int j = 0; j < 15; j++) {
EXPECT_EQ(
compositeAndResult[i][j],
inputs[i].first & inputs[size / 16 + 15 * i + j].first);
inputs[i].first && inputs[size / 16 + 15 * i + j].first);
EXPECT_EQ(
compositeAndResult[j + composite3EndIndex][i],
inputs[i].first & inputs[size / 16 + 15 * i + j].first);
inputs[i].first && inputs[size / 16 + 15 * i + j].first);
}
}

for (int i = 0; i < size / 8; i++) {
for (int j = 0; j < 7; j++) {
EXPECT_EQ(
compositeAndResult[i + composite15EndIndex][j],
inputs[i].first & inputs[size / 8 + 7 * i + j].first);
inputs[i].first && inputs[size / 8 + 7 * i + j].first);
EXPECT_EQ(
compositeAndResult[j + batchComposite15EndIndex][i],
inputs[i].first & inputs[size / 8 + 7 * i + j].first);
inputs[i].first && inputs[size / 8 + 7 * i + j].first);
}
}

Expand All @@ -1221,10 +1221,10 @@ TEST_P(NonFreeAndTestFixture, TestAnd) {
for (int j = 0; j < 3; j++) {
EXPECT_EQ(
compositeAndResult[i + composite7EndIndex][j],
inputs[i].first & inputs[size / 4 + 3 * i + j].first);
inputs[i].first && inputs[size / 4 + 3 * i + j].first);
EXPECT_EQ(
compositeAndResult[j + batchComposite7EndIndex][i],
inputs[i].first & inputs[size / 4 + 3 * i + j].first);
inputs[i].first && inputs[size / 4 + 3 * i + j].first);
}
}
}
Expand Down Expand Up @@ -1360,8 +1360,8 @@ TEST(SecretShareEngineTest, TestFreeANDWithDummyComponents) {
EXPECT_EQ(rst1.size(), size / 2);
EXPECT_EQ(rst2.size(), size / 2);
for (int i = 0; i < size / 2; i++) {
EXPECT_EQ(rst1[i], inputs1[i].first & inputs1[i + size / 2].first);
EXPECT_EQ(rst2[i], inputs2[i].first & inputs2[i + size / 2].first);
EXPECT_EQ(rst1[i], inputs1[i].first && inputs1[i + size / 2].first);
EXPECT_EQ(rst2[i], inputs2[i].first && inputs2[i + size / 2].first);
}
}

Expand Down Expand Up @@ -1396,8 +1396,8 @@ TEST(SecretShareEngineTest, TestBatchFreeANDWithDummyComponents) {
assertPartyResultsConsistent);
EXPECT_EQ(rst1.size(), size / 2);
for (int i = 0; i < size / 2; i++) {
EXPECT_EQ(rst1[i], inputs1[i].first & inputs1[i + size / 2].first);
EXPECT_EQ(rst2[i], inputs2[i].first & inputs2[i + size / 2].first);
EXPECT_EQ(rst1[i], inputs1[i].first && inputs1[i + size / 2].first);
EXPECT_EQ(rst2[i], inputs2[i].first && inputs2[i + size / 2].first);
}
}

Expand Down

0 comments on commit 7c0d5eb

Please sign in to comment.