Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some warnings in SmallPtrSetTest #77956

Closed
wants to merge 1 commit into from

Conversation

spacey-sooty
Copy link

Warnings are related to places which should use braces

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 12, 2024

@llvm/pr-subscribers-llvm-adt

Author: Isaac Turner (spacey-sooty)

Changes

Warnings are related to places which should use braces


Full diff: https://github.com/llvm/llvm-project/pull/77956.diff

1 Files Affected:

  • (modified) llvm/unittests/ADT/SmallPtrSetTest.cpp (+69-37)
diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp
index a97f2617cbf707..7a71caaa2317c3 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)
+  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)
+  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)
+  for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i) {
       (**I)++;
+  }
   EXPECT_EQ(4, i);
-  for(i=0; i<8; ++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)
+  for(iter I=s.begin(), E=s.end(); I!=E; ++I, ++i) {
       (**I)++;
-  for(i=0; i<8; ++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));
+  }
 }

Copy link

github-actions bot commented Jan 12, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warnings are related to places which should use braces

Could you paste a few of these warnings to here? I don't see warnings with my build and I'm curious what the compiler is complaining about.

In general, the llvm coding style doesn't require braces around single-line if/for statements like this: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements.

I think it makes sense to add these with for (...) if (...) ... ; else (...); like you did in a few places, but not to add it everywhere.

@spacey-sooty
Copy link
Author

Warnings are related to places which should use braces

Could you paste a few of these warnings to here? I don't see warnings with my build and I'm curious what the compiler is complaining about.

In general, the llvm coding style doesn't require braces around single-line if/for statements like this: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements.

I think it makes sense to add these with for (...) if (...) ... ; else (...); like you did in a few places, but not to add it everywhere.

I probably should've specified the warnings were from Clangd. The warnings were a lot of "Statement should be inside braces (fix available) [readability-braces-around-statement]"

@dwblaikie
Copy link
Collaborator

Warnings are related to places which should use braces

Could you paste a few of these warnings to here? I don't see warnings with my build and I'm curious what the compiler is complaining about.
In general, the llvm coding style doesn't require braces around single-line if/for statements like this: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements.
I think it makes sense to add these with for (...) if (...) ... ; else (...); like you did in a few places, but not to add it everywhere.

I probably should've specified the warnings were from Clangd. The warnings were a lot of "Statement should be inside braces (fix available) [readability-braces-around-statement]"

That's in contradiction to LLVM's style (both years of convention, and I think we actually explicitly enumerated it not so long ago: https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements )- probably turn that check off when working with LLVM code.

@dwblaikie dwblaikie closed this Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants