[llvm] r195260 - Add a test for assignment operator behavior which was changed in

NAKAMURA Takumi geek4civic at gmail.com
Fri Nov 22 20:24:34 PST 2013


+  // Self assign as well.
+  (s2 = s2).insert(&buf[3]);

It makes vg_leak complain;

==27072== Source and destination overlap in memcpy(0x7ff000720, 0x7ff000720, 32)
==27072==    at 0x4C296BE: memcpy (mc_replace_strmem.c:838)
==27072==    by 0x600062:
llvm::SmallPtrSetImpl::CopyFrom(llvm::SmallPtrSetImpl const&)
(SmallPtrSet.cpp:248)
==27072==    by 0x54364C: llvm::SmallPtrSet<int*,
4u>::operator=(llvm::SmallPtrSet<int*, 4u> const&) (SmallPtrSet.h:296)
==27072==    by 0x53F6DA: SmallPtrSetTest_Assignment_Test::TestBody()
(SmallPtrSetTest.cpp:32)

Could we tweak SmallPtrSet to appease vg_leak?

  // Copy over the contents from the other set
  memcpy(CurArray, RHS.CurArray, sizeof(void*)*CurArraySize);

1) Use memmove() instead.
2) Check LHS != RHS before memcpy().
*) Any idea?

2013/11/21 Chandler Carruth <chandlerc at gmail.com>:
> Author: chandlerc
> Date: Wed Nov 20 12:21:25 2013
> New Revision: 195260
>
> URL: http://llvm.org/viewvc/llvm-project?rev=195260&view=rev
> Log:
> Add a test for assignment operator behavior which was changed in
> r195239, as well as a comment about the fact that assigning over
> a moved-from object was in fact tested. Addresses some of the review
> feedback on r195239.
>
> Modified:
>     llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp
>
> Modified: llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp?rev=195260&r1=195259&r2=195260&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp (original)
> +++ llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp Wed Nov 20 12:21:25 2013
> @@ -16,7 +16,30 @@
>
>  using namespace llvm;
>
> -// SmallPtrSet swapping test.
> +TEST(SmallPtrSetTest, Assignment) {
> +  int buf[8];
> +  for (int i = 0; i < 8; ++i)
> +    buf[i] = 0;
> +
> +  SmallPtrSet<int *, 4> s1;
> +  s1.insert(&buf[0]);
> +  s1.insert(&buf[1]);
> +
> +  SmallPtrSet<int *, 4> s2;
> +  (s2 = s1).insert(&buf[2]);
> +
> +  // Self assign as well.
> +  (s2 = s2).insert(&buf[3]);
> +
> +  s1 = s2;
> +  EXPECT_EQ(4U, s1.size());
> +  for (int i = 0; i < 8; ++i)
> +    if (i < 4)
> +      EXPECT_TRUE(s1.count(&buf[i]));
> +    else
> +      EXPECT_FALSE(s1.count(&buf[i]));
> +}
> +
>  TEST(SmallPtrSetTest, GrowthTest) {
>    int i;
>    int buf[8];
> @@ -112,6 +135,7 @@ TEST(SmallPtrSetTest, CopyAndMoveTest) {
>      else
>        EXPECT_FALSE(s3.count(&buf[i]));
>
> +  // Move assign to the moved-from object.
>    s1 = llvm_move(s3);
>    EXPECT_EQ(4U, s1.size());
>    for (int i = 0; i < 8; ++i)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list