[llvm] [NFC] Fix dangling-else warning (PR #112817)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 20:14:14 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Jinsong Ji (jsji)
<details>
<summary>Changes</summary>
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.
Fix warnings:
llvm/unittests/ProfileData/CoverageMappingTest.cpp: In member function ‘virtual void {anonymous}::CoverageMappingTest_TVIdxBuilder_Test::TestBody()’:
llvm/unittests/ProfileData/CoverageMappingTest.cpp:1116:10: error: suggest explicit braces to avoid ambiguous ‘else’ [-Werror=dangling-else]
1116 | if (Node.NextIDs[C] < 0)
---
Full diff: https://github.com/llvm/llvm-project/pull/112817.diff
5 Files Affected:
- (modified) llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp (+2-1)
- (modified) llvm/unittests/IR/AttributesTest.cpp (+2-2)
- (modified) llvm/unittests/IR/PatternMatch.cpp (+8-4)
- (modified) llvm/unittests/Object/ELFObjectFileTest.cpp (+2-1)
- (modified) llvm/unittests/ProfileData/CoverageMappingTest.cpp (+2-1)
``````````diff
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index fe04cbbce12dcd..6b6ee1a3f2cbcf 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -2936,8 +2936,9 @@ TEST_F(OpenMPIRBuilderTest, CriticalDirective) {
const DataLayout &DL = M->getDataLayout();
const llvm::Align TypeAlign = DL.getABITypeAlign(CriticalNamePtrTy);
const llvm::Align PtrAlign = DL.getPointerABIAlignment(GV->getAddressSpace());
- if (const llvm::MaybeAlign Alignment = GV->getAlign())
+ if (const llvm::MaybeAlign Alignment = GV->getAlign()) {
EXPECT_EQ(*Alignment, std::max(TypeAlign, PtrAlign));
+ }
}
TEST_F(OpenMPIRBuilderTest, OrderedDirectiveDependSource) {
diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp
index f73f2b20e9fea5..97aaf42570d1fe 100644
--- a/llvm/unittests/IR/AttributesTest.cpp
+++ b/llvm/unittests/IR/AttributesTest.cpp
@@ -468,9 +468,9 @@ TEST(Attributes, SetIntersect) {
AS0 = AttributeSet::get(C0, AB0);
Res = AS0.intersectWith(C0, AS1);
ASSERT_EQ(Res.has_value(), CanDrop);
- if (CanDrop)
+ if (CanDrop) {
ASSERT_FALSE(Res->hasAttributes());
-
+ }
AS1 = AttributeSet::get(C1, AB0);
Res = AS0.intersectWith(C0, AS1);
ASSERT_TRUE(Res.has_value());
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 367ba6ab52a596..e6a08fd713bdda 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -637,20 +637,23 @@ TEST_F(PatternMatchTest, CheckedInt) {
CRes = nullptr;
EXPECT_EQ(CheckUgt1(APVal), m_CheckedInt(CheckUgt1).match(C));
EXPECT_EQ(CheckUgt1(APVal), m_CheckedInt(CRes, CheckUgt1).match(C));
- if (CheckUgt1(APVal))
+ if (CheckUgt1(APVal)) {
EXPECT_EQ(CRes, C);
+ }
CRes = nullptr;
EXPECT_EQ(CheckNonZero(APVal), m_CheckedInt(CheckNonZero).match(C));
EXPECT_EQ(CheckNonZero(APVal), m_CheckedInt(CRes, CheckNonZero).match(C));
- if (CheckNonZero(APVal))
+ if (CheckNonZero(APVal)) {
EXPECT_EQ(CRes, C);
+ }
CRes = nullptr;
EXPECT_EQ(CheckPow2(APVal), m_CheckedInt(CheckPow2).match(C));
EXPECT_EQ(CheckPow2(APVal), m_CheckedInt(CRes, CheckPow2).match(C));
- if (CheckPow2(APVal))
+ if (CheckPow2(APVal)) {
EXPECT_EQ(CRes, C);
+ }
};
@@ -710,8 +713,9 @@ TEST_F(PatternMatchTest, CheckedInt) {
EXPECT_EQ(Expec, m_CheckedInt(CRes, CheckFn).match(C));
if (Expec) {
EXPECT_NE(CRes, nullptr);
- if (AllSame)
+ if (AllSame) {
EXPECT_EQ(CRes, C);
+ }
}
};
auto DoVecCheck = [&](ArrayRef<std::optional<int8_t>> Vals) {
diff --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp
index c13dc0e3fab898..153ac560179985 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -1244,8 +1244,9 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
}
EXPECT_EQ(PGOAnalyses, *ExpectedPGO);
for (auto &&[BB, PGO] : llvm::zip(*BBAddrMaps, PGOAnalyses)) {
- if (PGO.FeatEnable.BBFreq || PGO.FeatEnable.BrProb)
+ if (PGO.FeatEnable.BBFreq || PGO.FeatEnable.BrProb) {
EXPECT_EQ(BB.getNumBBEntries(), PGO.BBEntries.size());
+ }
}
}
};
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index ef147674591c51..288bf8e254d498 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -1113,8 +1113,9 @@ TEST(CoverageMappingTest, TVIdxBuilder) {
EXPECT_EQ(Node.Width, IndicesRefs[I].Width);
for (int C = 0; C < 2; ++C) {
auto Index = TheBuilder.Indices[I][C];
- if (Node.NextIDs[C] < 0)
+ if (Node.NextIDs[C] < 0) {
EXPECT_TRUE(Decisions.insert({Index, Node.Width}).second);
+ }
}
#endif
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/112817
More information about the llvm-commits
mailing list