[llvm] fix some warnings in SmallPtrSetTest (PR #77956)

Isaac Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 10:20:55 PST 2024


https://github.com/spacey-sooty updated https://github.com/llvm/llvm-project/pull/77956

>From 1d5c1d8525b6f5afb56fd5f0014b1dc026323df4 Mon Sep 17 00:00:00 2001
From: Isaac Turner <spacey_sooty at outlook.com>
Date: Sat, 13 Jan 2024 02:12:54 +0800
Subject: [PATCH] fix some warnings in SmallPtrSetTest

---
 llvm/unittests/ADT/SmallPtrSetTest.cpp | 118 ++++++++++++++++---------
 1 file changed, 75 insertions(+), 43 deletions(-)

diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp
index a97f2617cbf707..b1c0be714f1c2b 100644
--- a/llvm/unittests/ADT/SmallPtrSetTest.cpp
+++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp
@@ -20,8 +20,9 @@ using namespace llvm;
 
 TEST(SmallPtrSetTest, Assignment) {
   int buf[8];
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 8; ++i) {
     buf[i] = 0;
+  }
 
   SmallPtrSet<int *, 4> s1 = {&buf[0], &buf[1]};
   SmallPtrSet<int *, 4> s2;
@@ -32,27 +33,32 @@ TEST(SmallPtrSetTest, Assignment) {
 
   s1 = s2;
   EXPECT_EQ(4U, s1.size());
-  for (int i = 0; i < 8; ++i)
-    if (i < 4)
+  for (int i = 0; i < 8; ++i) {
+    if (i < 4) {
       EXPECT_TRUE(s1.count(&buf[i]));
-    else
+    } else {
       EXPECT_FALSE(s1.count(&buf[i]));
+    }
+  }
 
   // Assign and insert with initializer lists, and ones that contain both
   // duplicates and out-of-order elements.
   (s2 = {&buf[6], &buf[7], &buf[6]}).insert({&buf[5], &buf[4]});
-  for (int i = 0; i < 8; ++i)
-    if (i < 4)
+  for (int i = 0; i < 8; ++i) {
+    if (i < 4) {
       EXPECT_FALSE(s2.count(&buf[i]));
-    else
+    } else {
       EXPECT_TRUE(s2.count(&buf[i]));
+    }
+  }
 }
 
 TEST(SmallPtrSetTest, GrowthTest) {
   int i;
   int buf[8];
-  for(i=0; i<8; ++i) buf[i]=0;
-
+  for (i = 0; i < 8; ++i) {
+    buf[i] = 0;
+  }
 
   SmallPtrSet<int *, 4> s;
   typedef SmallPtrSet<int *, 4>::iterator iter;
@@ -64,8 +70,9 @@ TEST(SmallPtrSetTest, GrowthTest) {
   EXPECT_EQ(4U, s.size());
 
   i = 0;
-  for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
-      (**I)++;
+  for (iter I = s.begin(), E = s.end(); I != E; ++I, ++i) {
+    (**I)++;
+  }
   EXPECT_EQ(4, i);
   for(i=0; i<8; ++i)
       EXPECT_EQ(i<4?1:0,buf[i]);
@@ -76,8 +83,9 @@ TEST(SmallPtrSetTest, GrowthTest) {
   s.insert(&buf[7]);
 
   i = 0;
-  for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
-      (**I)++;
+  for (iter I = s.begin(), E = s.end(); I != E; ++I, ++i) {
+    (**I)++;
+  }
   EXPECT_EQ(8, i);
   s.erase(&buf[4]);
   s.erase(&buf[5]);
@@ -86,26 +94,35 @@ TEST(SmallPtrSetTest, GrowthTest) {
   EXPECT_EQ(4U, s.size());
 
   i = 0;
-  for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
-      (**I)++;
+  for (iter I = s.begin(), E = s.end(); I != E; ++I, ++i) {
+    (**I)++;
+  }
   EXPECT_EQ(4, i);
-  for(i=0; i<8; ++i)
-      EXPECT_EQ(i<4?3:1,buf[i]);
+  for (i = 0; i < 8; ++i) {
+    EXPECT_EQ(i < 4 ? 3 : 1, buf[i]);
+  }
 
   s.clear();
-  for(i=0; i<8; ++i) buf[i]=0;
-  for(i=0; i<128; ++i) s.insert(&buf[i%8]); // test repeated entires
+  for (i = 0; i < 8; ++i) {
+    buf[i] = 0;
+  }
+  for (i = 0; i < 128; ++i) {
+    s.insert(&buf[i % 8]); // test repeated entires
+  }
   EXPECT_EQ(8U, s.size());
-  for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i)
-      (**I)++;
-  for(i=0; i<8; ++i)
-      EXPECT_EQ(1,buf[i]);
+  for (iter I = s.begin(), E = s.end(); I != E; ++I, ++i) {
+    (**I)++;
+  }
+  for (i = 0; i < 8; ++i) {
+    EXPECT_EQ(1, buf[i]);
+  }
 }
 
 TEST(SmallPtrSetTest, CopyAndMoveTest) {
   int buf[8];
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 8; ++i) {
     buf[i] = 0;
+  }
 
   SmallPtrSet<int *, 4> s1;
   s1.insert(&buf[0]);
@@ -113,37 +130,45 @@ TEST(SmallPtrSetTest, CopyAndMoveTest) {
   s1.insert(&buf[2]);
   s1.insert(&buf[3]);
   EXPECT_EQ(4U, s1.size());
-  for (int i = 0; i < 8; ++i)
-    if (i < 4)
+  for (int i = 0; i < 8; ++i) {
+    if (i < 4) {
       EXPECT_TRUE(s1.count(&buf[i]));
-    else
+    } else {
       EXPECT_FALSE(s1.count(&buf[i]));
+    }
+  }
 
   SmallPtrSet<int *, 4> s2(s1);
   EXPECT_EQ(4U, s2.size());
-  for (int i = 0; i < 8; ++i)
-    if (i < 4)
+  for (int i = 0; i < 8; ++i) {
+    if (i < 4) {
       EXPECT_TRUE(s2.count(&buf[i]));
-    else
+    } else {
       EXPECT_FALSE(s2.count(&buf[i]));
+    }
+  }
 
   s1 = s2;
   EXPECT_EQ(4U, s1.size());
   EXPECT_EQ(4U, s2.size());
-  for (int i = 0; i < 8; ++i)
-    if (i < 4)
+  for (int i = 0; i < 8; ++i) {
+    if (i < 4) {
       EXPECT_TRUE(s1.count(&buf[i]));
-    else
+    } else {
       EXPECT_FALSE(s1.count(&buf[i]));
+    }
+  }
 
   SmallPtrSet<int *, 4> s3(std::move(s1));
   EXPECT_EQ(4U, s3.size());
   EXPECT_TRUE(s1.empty());
-  for (int i = 0; i < 8; ++i)
-    if (i < 4)
+  for (int i = 0; i < 8; ++i) {
+    if (i < 4) {
       EXPECT_TRUE(s3.count(&buf[i]));
-    else
+    } else {
       EXPECT_FALSE(s3.count(&buf[i]));
+    }
+  }
 
   // Move assign into the moved-from object. Also test move of a non-small
   // container.
@@ -154,15 +179,17 @@ TEST(SmallPtrSetTest, CopyAndMoveTest) {
   s1 = std::move(s3);
   EXPECT_EQ(8U, s1.size());
   EXPECT_TRUE(s3.empty());
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 8; ++i) {
     EXPECT_TRUE(s1.count(&buf[i]));
+  }
 
   // Copy assign into a moved-from object.
   s3 = s1;
   EXPECT_EQ(8U, s3.size());
   EXPECT_EQ(8U, s1.size());
-  for (int i = 0; i < 8; ++i)
+  for (int i = 0; i < 8; ++i) {
     EXPECT_TRUE(s3.count(&buf[i]));
+  }
 }
 
 TEST(SmallPtrSetTest, SwapTest) {
@@ -293,15 +320,18 @@ TEST(SmallPtrSetTest, dereferenceAndIterate) {
 
   // Iterate from each and count how many times each element is found.
   int Found[sizeof(Ints)/sizeof(int)] = {0};
-  for (int &I : Ints)
-    for (auto F = S.find(&I), E = S.end(); F != E; ++F)
+  for (int &I : Ints) {
+    for (auto F = S.find(&I), E = S.end(); F != E; ++F) {
       ++Found[*F - Ints];
+    }
+  }
 
   // Sort.  We should hit the first element just once and the final element N
   // times.
   llvm::sort(Found);
-  for (auto F = std::begin(Found), E = std::end(Found); F != E; ++F)
+  for (auto F = std::begin(Found), E = std::end(Found); F != E; ++F) {
     EXPECT_EQ(F - Found + 1, *F);
+  }
 }
 
 // Verify that const pointers work for count and find even when the underlying
@@ -402,10 +432,12 @@ TEST(SmallPtrSetTest, InsertIterator) {
   int Vals[5] = {11, 22, 33, 44, 55};
   int *Buf[5] = {&Vals[0], &Vals[1], &Vals[2], &Vals[3], &Vals[4]};
 
-  for (int *Ptr : Buf)
+  for (int *Ptr : Buf) {
     Set.insert(Set.begin(), Ptr);
+  }
 
   // Ensure that all of the values were copied into the set.
-  for (const auto *Ptr : Buf)
+  for (const auto *Ptr : Buf) {
     EXPECT_TRUE(Set.contains(Ptr));
+  }
 }



More information about the llvm-commits mailing list