This is an archive of the discontinued LLVM Phabricator instance.

Fix off by one error in Bitfields
ClosedPublic

Authored by gchatelet on Jul 6 2020, 1:00 AM.

Diff Detail

Event Timeline

gchatelet created this revision.Jul 6 2020, 1:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2020, 1:00 AM
This revision was not accepted when it landed; it landed in state Needs Review.Jul 6 2020, 1:52 AM
This revision was automatically updated to reflect the committed changes.

Can you add a unit test for this ?

Can you add a unit test for this ?

I'll add the following test as a separate commit if it LGTY.
Note: I can't use EXPECT_EQ because it takes the arguments by const & and the properties are static constexpr, the compiler complains about undefined reference.

TEST(BitfieldsTest, Properties) {
  using A = Bitfield::Element<bool, 0, 1>;
  EXPECT_TRUE(A::FirstBit == 0U);
  EXPECT_TRUE(A::LastBit == 0U);
  EXPECT_TRUE(A::Shift == 0U);
  EXPECT_TRUE(A::Bits == 1U);

  using B = Bitfield::Element<unsigned, 3, 4>;
  EXPECT_TRUE(B::FirstBit == 3U);
  EXPECT_TRUE(B::LastBit == 6U);
  EXPECT_TRUE(B::Shift == 3U);
  EXPECT_TRUE(B::Bits == 4U);
}

Can you add a unit test for this ?

I'll add the following test as a separate commit if it LGTY.
Note: I can't use EXPECT_EQ because it takes the arguments by const & and the properties are static constexpr, the compiler complains about undefined reference.

TEST(BitfieldsTest, Properties) {
  using A = Bitfield::Element<bool, 0, 1>;
  EXPECT_TRUE(A::FirstBit == 0U);
  EXPECT_TRUE(A::LastBit == 0U);
  EXPECT_TRUE(A::Shift == 0U);
  EXPECT_TRUE(A::Bits == 1U);

  using B = Bitfield::Element<unsigned, 3, 4>;
  EXPECT_TRUE(B::FirstBit == 3U);
  EXPECT_TRUE(B::LastBit == 6U);
  EXPECT_TRUE(B::Shift == 3U);
  EXPECT_TRUE(B::Bits == 4U);
}

SG