[llvm-commits] [llvm] r159201 - in /llvm/trunk: include/llvm/Support/IntegersSubsetMapping.h unittests/Support/IntegersSubsetTest.cpp

Matt Beaumont-Gay matthewbg at google.com
Tue Jun 26 08:45:01 PDT 2012


Hi Stepan,

On Tue, Jun 26, 2012 at 4:57 AM, Stepan Dyatkovskiy <stpworld at narod.ru> wrote:
> Modified: llvm/trunk/unittests/Support/IntegersSubsetTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/IntegersSubsetTest.cpp?rev=159201&r1=159200&r2=159201&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Support/IntegersSubsetTest.cpp (original)
> +++ llvm/trunk/unittests/Support/IntegersSubsetTest.cpp Tue Jun 26 06:57:43 2012
> @@ -21,6 +21,7 @@
>
>   class Int : public APInt {
>   public:
> +    Int() {}
>     Int(uint64_t V) : APInt(64, V) {}
>     Int(const APInt& Src) : APInt(Src) {}
>     bool operator < (const APInt& RHS) const { return ult(RHS); }
> @@ -178,4 +179,146 @@
>       EXPECT_EQ(CaseIt->second.getItem(0), Range(Int(i * 10), Int(i * 10 + 9)));
>     }
>   }
> +
> +  typedef unsigned unsigned_pair[2];
> +  typedef unsigned_pair unsigned_ranges[];
> +
> +  void TestDiff(
> +      const unsigned_ranges LHS,
> +      unsigned LSize,
> +      const unsigned_ranges RHS,
> +      unsigned RSize,
> +      const unsigned_ranges ExcludeRes,
> +      unsigned ExcludeResSize,
> +      const unsigned_ranges IntersectRes,
> +      unsigned IntersectResSize
> +      ) {
> +    Mapping::RangesCollection Ranges;
> +
> +    Mapping LHSMapping;
> +    for (unsigned i = 0; i < LSize; ++i)
> +      Ranges.push_back(Range(Int(LHS[i][0]), Int(LHS[i][1])));
> +    LHSMapping.add(Ranges);
> +
> +    Ranges.clear();
> +
> +    Mapping RHSMapping;
> +    for (unsigned i = 0; i < RSize; ++i)
> +      Ranges.push_back(Range(Int(RHS[i][0]), Int(RHS[i][1])));
> +    RHSMapping.add(Ranges);
> +
> +    Mapping LExclude, Intersection;
> +
> +    LHSMapping.diff(&LExclude, &Intersection, 0, RHSMapping);
> +
> +    if (ExcludeResSize) {
> +      EXPECT_EQ(LExclude.size(), ExcludeResSize);
> +
> +      unsigned i = 0;
> +      for (Mapping::RangeIterator rei = LExclude.begin(),
> +           e = LExclude.end(); rei != e; ++rei, ++i)
> +        EXPECT_EQ(rei->first, Range(ExcludeRes[i][0], ExcludeRes[i][1]));
> +    } else
> +      EXPECT_TRUE(LExclude.empty());
> +
> +    if (IntersectResSize) {
> +      EXPECT_EQ(Intersection.size(), IntersectResSize);
> +
> +      unsigned i = 0;
> +      for (Mapping::RangeIterator ii = Intersection.begin(),
> +           e = Intersection.end(); ii != e; ++ii, ++i)
> +        EXPECT_EQ(ii->first, Range(IntersectRes[i][0], IntersectRes[i][1]));
> +    } else
> +      EXPECT_TRUE(Intersection.empty());
> +
> +    LExclude.clear();
> +    Intersection.clear();
> +    RHSMapping.diff(0, &Intersection, &LExclude, LHSMapping);
> +
> +    // Check LExclude again.
> +    if (ExcludeResSize) {
> +      EXPECT_EQ(LExclude.size(), ExcludeResSize);
> +
> +      unsigned i = 0;
> +      for (Mapping::RangeIterator rei = LExclude.begin(),
> +           e = LExclude.end(); rei != e; ++rei, ++i)
> +        EXPECT_EQ(rei->first, Range(ExcludeRes[i][0], ExcludeRes[i][1]));
> +    } else
> +      EXPECT_TRUE(LExclude.empty());
> +  }
> +
> +  TEST(IntegersSubsetTest, DiffTest) {
> +    {
> +      unsigned_ranges LHS = { { 0, 4 }, { 7, 10 }, { 13, 17 } };
> +      unsigned_ranges RHS = { { 3, 14 } };
> +      unsigned_ranges ExcludeRes = { { 0, 2 }, { 15, 17 } };
> +      unsigned_ranges IntersectRes = { { 3, 4 }, { 7, 10 }, { 13, 14 } };
> +
> +      TestDiff(LHS, 3, RHS, 1, ExcludeRes, 2, IntersectRes, 3);
> +    }
> +
> +    {
> +      unsigned_ranges LHS = { { 0, 4 }, { 7, 10 }, { 13, 17 } };
> +      unsigned_ranges RHS = { { 0, 4 }, { 13, 17 } };
> +      unsigned_ranges ExcludeRes = { { 7, 10 } };
> +      unsigned_ranges IntersectRes = { { 0, 4 }, { 13, 17 } };
> +
> +      TestDiff(LHS, 3, RHS, 2, ExcludeRes, 1, IntersectRes, 2);
> +    }
> +
> +    {
> +      unsigned_ranges LHS = { { 0, 17 } };
> +      unsigned_ranges RHS = { { 1, 5 }, { 10, 12 }, { 15, 16 } };
> +      unsigned_ranges ExcludeRes =
> +          { { 0, 0 }, { 6, 9 }, { 13, 14 }, { 17, 17 } };
> +      unsigned_ranges IntersectRes = { { 1, 5 }, { 10, 12 }, { 15, 16 } };
> +
> +      TestDiff(LHS, 1, RHS, 3, ExcludeRes, 4, IntersectRes, 3);
> +    }
> +
> +    {
> +      unsigned_ranges LHS = { { 2, 4 } };
> +      unsigned_ranges RHS = { { 0, 5 } };
> +      unsigned_ranges ExcludeRes = { {-1UL, -1UL} };

This breaks the build with -std=c++11, since converting -1 to unsigned
is a narrowing conversion.

-Matt




More information about the llvm-commits mailing list