[Mlir-commits] [clang] [flang] [lldb] [llvm] [mlir] [clang] Add -Wbool-integral-comparison (PR #194180)

Andrei Sabalenka llvmlistbot at llvm.org
Fri May 1 02:37:41 PDT 2026


https://github.com/mechakotik updated https://github.com/llvm/llvm-project/pull/194180

>From cc953cc02ec6e5359e48000f25ea045bdd2c95e4 Mon Sep 17 00:00:00 2001
From: Andrei Sabalenka <mechakotik at gmail.com>
Date: Sun, 26 Apr 2026 00:21:29 +0300
Subject: [PATCH 1/2] [clang] Add -Wbool-integral-comparison

Warn on suspicious comparisons of bool and non-constant integral or enumeration expressions, like this:

bool b = ...;
int i = ...;
bool res = (b == i);

The bool operand is converted to an integral value that can only be 0 or 1, so comparing it with an arbitrary number is often unintentional.

This warning does not apply to integral constant expressions. Comparisons against 0 and 1 are common intentional patterns, while comparisons against other constants are better handled by existing tautological comparison warnings.

It also does not apply to dependent template comparisons or integral expressions known to have a boolean value, such as unsigned one-bit bit fields.

This warning is enabled by -Wextra.
---
 clang/docs/ReleaseNotes.rst                   | 27 ++++++
 clang/include/clang/Basic/DiagnosticGroups.td |  2 +
 .../clang/Basic/DiagnosticSemaKinds.td        |  5 +
 clang/lib/Sema/SemaChecking.cpp               | 29 +++++-
 .../SemaCXX/warn-bool-integral-comparison.cpp | 96 +++++++++++++++++++
 5 files changed, 158 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/warn-bool-integral-comparison.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c408196c3816b..cd1f41bcff800 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -472,6 +472,33 @@ Improvements to Clang's diagnostics
 
 - Removed the body of lambdas from some diagnostic messages.
 
+- Added ``-Wbool-integral-comparison`` to warn on suspicious comparisons of ``bool``
+  and non-constant integral or enumeration expressions. For example:
+
+  .. code-block:: c++
+
+    bool b = true;
+    int i = 2;
+    bool res = (b == i);
+
+  Clang will warn:
+
+  .. code-block:: text
+
+    warning: comparison between 'bool' and integral type 'int' is suspicious; the 'bool'
+    operand is converted to an integral value that can only be 0 or 1 [-Wbool-integral-comparison]
+    bool res = (b == i);
+                ~ ^  ~
+
+  This warning does not apply to integral constant expressions. Comparisons against
+  0 and 1 are common intentional patterns, while comparisons against other constants
+  are better handled by existing tautological comparison warnings.
+
+  It also does not apply to dependent template comparisons or integral expressions
+  known to have a boolean value, such as unsigned one-bit bit fields.
+
+  This warning is enabled by ``-Wextra``. (#GH194180)
+
 Improvements to Clang's time-trace
 ----------------------------------
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 2b3055d6d6bdd..01b96c9475309 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -946,6 +946,7 @@ def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor,
 
 def : DiagGroup<"sign-promo">;
 def SignCompare : DiagGroup<"sign-compare">;
+def BoolIntegralComparison : DiagGroup<"bool-integral-comparison">;
 def SwitchDefault  : DiagGroup<"switch-default">;
 def : DiagGroup<"synth">;
 def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">;
@@ -1376,6 +1377,7 @@ def Extra : DiagGroup<"extra", [
     SemiBeforeMethodBody,
     MissingMethodReturnType,
     SignCompare,
+    BoolIntegralComparison,
     UnusedParameter,
     UnusedButSetParameter,
     NullPointerArithmetic,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1302c4296885b..fb00302ad7baf 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8134,6 +8134,11 @@ def warn_tautological_compare_value_range : Warning<
 def warn_mixed_sign_comparison : Warning<
   "comparison of integers of different signs: %0 and %1">,
   InGroup<SignCompare>, DefaultIgnore;
+def warn_bool_integral_comparison : Warning<
+  "comparison between %0 and %select{integral|enumeration}2 type %1 is "
+  "suspicious; the %0 operand is converted to an integral value that can only "
+  "be 0 or 1">,
+  InGroup<BoolIntegralComparison>, DefaultIgnore;
 def warn_out_of_range_compare : Warning<
   "result of comparison of %select{constant %0|true|false}1 with "
   "%select{expression of type %2|boolean expression}3 is always %4">,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index eb957df6f1e97..a3ac33ff86599 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12391,7 +12391,32 @@ static void AnalyzeImpConvsInComparison(Sema &S, BinaryOperator *E) {
   AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
 }
 
-/// Implements -Wsign-compare.
+static void CheckBoolIntegralComparison(Sema &S, BinaryOperator *E) {
+  if (S.inTemplateInstantiation())
+    return;
+
+  Expr *LHS = E->getLHS()->IgnoreImpCasts();
+  Expr *RHS = E->getRHS()->IgnoreImpCasts();
+  QualType LHSType = LHS->getType();
+  QualType RHSType = RHS->getType();
+
+  if (LHSType->isBooleanType() == RHSType->isBooleanType())
+    return;
+
+  QualType BoolType = LHSType->isBooleanType() ? LHSType : RHSType;
+  QualType OtherType = LHSType->isBooleanType() ? RHSType : LHSType;
+  Expr *OtherExpr = LHSType->isBooleanType() ? RHS : LHS;
+  if (!OtherType->isIntegralOrEnumerationType() ||
+      OtherExpr->isIntegerConstantExpr(S.Context) ||
+      OtherExpr->isKnownToHaveBooleanValue(/*Semantic=*/false))
+    return;
+
+  S.Diag(E->getOperatorLoc(), diag::warn_bool_integral_comparison)
+      << BoolType << OtherType << OtherType->isEnumeralType()
+      << LHS->getSourceRange() << RHS->getSourceRange();
+}
+
+/// Analyze comparison operators for comparison-related warnings.
 ///
 /// \param E the binary operator to check for warnings
 static void AnalyzeComparison(Sema &S, BinaryOperator *E) {
@@ -12433,6 +12458,8 @@ static void AnalyzeComparison(Sema &S, BinaryOperator *E) {
       if (CheckTautologicalComparison(S, E, Const, Other, Value, RhsConstant))
         return AnalyzeImpConvsInComparison(S, E);
     }
+
+    CheckBoolIntegralComparison(S, E);
   }
 
   if (!T->hasUnsignedIntegerRepresentation()) {
diff --git a/clang/test/SemaCXX/warn-bool-integral-comparison.cpp b/clang/test/SemaCXX/warn-bool-integral-comparison.cpp
new file mode 100644
index 0000000000000..462695f61b990
--- /dev/null
+++ b/clang/test/SemaCXX/warn-bool-integral-comparison.cpp
@@ -0,0 +1,96 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wbool-integral-comparison %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wextra %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,priority -Wbool-integral-comparison -Wtautological-unsigned-zero-compare %s
+// RUN: %clang_cc1 -fsyntax-only -verify=wall -Wall %s
+
+// wall-no-diagnostics
+
+void integral_comparisons(bool b, char c, int i, unsigned u, bool other) {
+  (void)(b == c); // expected-warning {{comparison between 'bool' and integral type 'char' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+  (void)(c != b); // expected-warning {{comparison between 'bool' and integral type 'char' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+  (void)(b < i);  // expected-warning {{comparison between 'bool' and integral type 'int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+  (void)(u >= b); // expected-warning {{comparison between 'bool' and integral type 'unsigned int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+
+  (void)(b == other);
+  (void)(b < other);
+}
+
+void reference_operands(bool b, bool &br, int i, int &ir) {
+  (void)(br == i);  // expected-warning {{comparison between 'bool' and integral type 'int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+  (void)(b == ir);  // expected-warning {{comparison between 'bool' and integral type 'int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+  (void)(ir == br); // expected-warning {{comparison between 'bool' and integral type 'int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+}
+
+void parenthesized_operands(bool b, char c) {
+  (void)((b) == (c)); // expected-warning {{comparison between 'bool' and integral type 'char' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+}
+
+void qualified_operands(const bool b, volatile char c) {
+  (void)(b == c); // expected-warning {{comparison between 'const bool' and integral type 'volatile char' is suspicious; the 'const bool' operand is converted to an integral value that can only be 0 or 1}}
+}
+
+typedef bool Bool;
+using Int = int;
+
+void alias_operands(Bool b, Int i) {
+  (void)(b == i); // expected-warning {{comparison between 'Bool' (aka 'bool') and integral type 'Int' (aka 'int') is suspicious; the 'Bool' operand is converted to an integral value that can only be 0 or 1}}
+}
+
+template <typename T> bool dependent_template_comparison(bool b, T t) {
+  return b == t;
+}
+
+void instantiate_template_comparison(bool b, int i) {
+  (void)dependent_template_comparison(b, i);
+}
+
+template <typename T> bool non_dependent_template_comparison(bool b, int i) {
+  return b == i; // expected-warning {{comparison between 'bool' and integral type 'int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+}
+
+struct BitFields {
+  unsigned one_bit : 1;
+  unsigned two_bits : 2;
+  int signed_one_bit : 1;
+};
+
+void bit_field_comparisons(bool b, BitFields bf, BitFields *bfp) {
+  (void)(b == bf.two_bits); // expected-warning {{comparison between 'bool' and integral type 'unsigned int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+  (void)(bf.signed_one_bit == b); // expected-warning {{comparison between 'bool' and integral type 'int' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+
+  (void)(b == bf.one_bit);
+  (void)(bfp->one_bit == b);
+}
+
+void constant_integral(bool b) {
+  constexpr int one = 1;
+  const int zero = 0;
+
+  (void)(b == 1);
+  (void)(0 != b);
+  (void)(b < one);
+  (void)(zero >= b);
+  (void)(true >= 'a');
+}
+
+enum E { e0, e1 };
+
+void enum_comparisons(bool b, E e) {
+  (void)(b == e); // expected-warning {{comparison between 'bool' and enumeration type 'E' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+  (void)(e != b); // expected-warning {{comparison between 'bool' and enumeration type 'E' is suspicious; the 'bool' operand is converted to an integral value that can only be 0 or 1}}
+}
+
+void constant_enum(bool b) {
+  constexpr E zero = e0;
+  const E one = e1;
+
+  (void)(b == e0);
+  (void)(e1 != b);
+  (void)(b == zero);
+  (void)(one != b);
+}
+
+void tautological_compare_priority(unsigned u) {
+  (void)(false <= u); // priority-warning {{comparison of 0 <= unsigned expression is always true}}
+  (void)(u >= false); // priority-warning {{comparison of unsigned expression >= 0 is always true}}
+}

>From 9e4da76a3917d131a0533b95e7590906504a6d9d Mon Sep 17 00:00:00 2001
From: Andrei Sabalenka <mechakotik at gmail.com>
Date: Fri, 1 May 2026 12:21:37 +0300
Subject: [PATCH 2/2] [NFC] Silence -Wbool-integral-comparison warnings across
 LLVM

---
 bolt/lib/Profile/BoltAddressTranslation.cpp        |  4 ++--
 clang/lib/CodeGen/CodeGenFunction.cpp              |  2 +-
 clang/lib/Serialization/ASTReaderStmt.cpp          |  4 ++--
 flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp   |  2 +-
 flang/unittests/Evaluate/uint128.cpp               | 14 +++++++-------
 lldb/source/ValueObject/ValueObject.cpp            |  2 +-
 llvm/include/llvm/CodeGen/DIE.h                    |  4 ++--
 llvm/include/llvm/Support/DataExtractor.h          |  2 +-
 llvm/lib/ExecutionEngine/JITLink/aarch32.cpp       |  2 +-
 llvm/lib/Target/AMDGPU/AMDGPUNextUseAnalysis.cpp   |  3 ++-
 .../Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp    |  2 +-
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp      |  2 +-
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp        |  3 ++-
 llvm/lib/Transforms/IPO/AttributorAttributes.cpp   |  2 +-
 mlir/lib/Rewrite/ByteCode.cpp                      |  2 +-
 15 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp b/bolt/lib/Profile/BoltAddressTranslation.cpp
index 2068c9efbcb44..cc404e1aef70f 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -185,7 +185,7 @@ template <bool Cold>
 void BoltAddressTranslation::writeMaps(uint64_t &PrevAddress, raw_ostream &OS) {
   const uint32_t NumFuncs =
       llvm::count_if(llvm::make_first_range(Maps), [&](const uint64_t Address) {
-        return Cold == ColdPartSource.count(Address);
+        return Cold == (ColdPartSource.count(Address) != 0);
       });
   encodeULEB128(NumFuncs, OS);
   LLVM_DEBUG(dbgs() << "Writing " << NumFuncs << (Cold ? " cold" : "")
@@ -194,7 +194,7 @@ void BoltAddressTranslation::writeMaps(uint64_t &PrevAddress, raw_ostream &OS) {
   for (auto &MapEntry : Maps) {
     const uint64_t Address = MapEntry.first;
     // Only process cold fragments in cold mode, and vice versa.
-    if (Cold != ColdPartSource.count(Address))
+    if (Cold != (ColdPartSource.count(Address) != 0))
       continue;
     // NB: in `writeMaps` we use the input address because hashes are saved
     // early in `saveMetadata` before output addresses are assigned.
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index b920266b59808..ad208c924a183 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -175,7 +175,7 @@ void CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(FPOptions FPFeatures) {
   auto mergeFnAttrValue = [&](StringRef Name, bool Value) {
     auto OldValue =
         CGF.CurFn->getFnAttribute(Name).getValueAsBool();
-    auto NewValue = OldValue & Value;
+    bool NewValue = OldValue && Value;
     if (OldValue != NewValue)
       CGF.CurFn->addFnAttr(Name, llvm::toStringRef(NewValue));
   };
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index 4ada1dc58042d..288eb345e4818 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -155,7 +155,7 @@ void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
   SmallVector<Stmt *, 16> Stmts;
   unsigned NumStmts = Record.readInt();
   unsigned HasFPFeatures = Record.readInt();
-  assert(S->hasStoredFPFeatures() == HasFPFeatures);
+  assert(static_cast<unsigned>(S->hasStoredFPFeatures()) == HasFPFeatures);
   while (NumStmts--)
     Stmts.push_back(Record.readSubStmt());
   S->setStmts(Stmts);
@@ -1160,7 +1160,7 @@ void ASTStmtReader::VisitCastExpr(CastExpr *E) {
   CurrentUnpackingBits.emplace(Record.readInt());
   E->setCastKind((CastKind)CurrentUnpackingBits->getNextBits(/*Width=*/7));
   unsigned HasFPFeatures = CurrentUnpackingBits->getNextBit();
-  assert(E->hasStoredFPFeatures() == HasFPFeatures);
+  assert(static_cast<unsigned>(E->hasStoredFPFeatures()) == HasFPFeatures);
 
   E->setSubExpr(Record.readSubExpr());
 
diff --git a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
index 5a4e517c13ef5..76280c1636897 100644
--- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
@@ -966,7 +966,7 @@ bool PPCIntrinsicLibrary::isNativeVecElemOrderOnLE() {
 bool PPCIntrinsicLibrary::changeVecElemOrder() {
   const auto triple{fir::getTargetTriple(builder.getModule())};
   return (triple.isLittleEndian() !=
-          converter->getLoweringOptions().getNoPPCNativeVecElemOrder());
+          (converter->getLoweringOptions().getNoPPCNativeVecElemOrder() != 0));
 }
 
 static mlir::FunctionType genMmaVpFuncType(mlir::MLIRContext *context,
diff --git a/flang/unittests/Evaluate/uint128.cpp b/flang/unittests/Evaluate/uint128.cpp
index 0b749abe1c080..1e34ba64ae4fb 100644
--- a/flang/unittests/Evaluate/uint128.cpp
+++ b/flang/unittests/Evaluate/uint128.cpp
@@ -66,13 +66,13 @@ static void TestVsNative(__uint128_t x, __uint128_t y) {
   TEST(ToNative(n) == y);
   TEST(ToNative(~m) == ~x);
   TEST(ToNative(-m) == -x);
-  TEST(ToNative(!m) == !x);
-  TEST(ToNative(m < n) == (x < y));
-  TEST(ToNative(m <= n) == (x <= y));
-  TEST(ToNative(m == n) == (x == y));
-  TEST(ToNative(m != n) == (x != y));
-  TEST(ToNative(m >= n) == (x >= y));
-  TEST(ToNative(m > n) == (x > y));
+  TEST(!m == !x);
+  TEST((m < n) == (x < y));
+  TEST((m <= n) == (x <= y));
+  TEST((m == n) == (x == y));
+  TEST((m != n) == (x != y));
+  TEST((m >= n) == (x >= y));
+  TEST((m > n) == (x > y));
   TEST(ToNative(m & n) == (x & y));
   TEST(ToNative(m | n) == (x | y));
   TEST(ToNative(m ^ n) == (x ^ y));
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 33f143bb4e3e2..762db9fd44b4b 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -358,7 +358,7 @@ bool ValueObject::IsLogicalTrue(Status &error) {
     switch (is_logical_true) {
     case eLazyBoolYes:
     case eLazyBoolNo:
-      return (is_logical_true == true);
+      return is_logical_true == eLazyBoolYes;
     case eLazyBoolCalculate:
       break;
     }
diff --git a/llvm/include/llvm/CodeGen/DIE.h b/llvm/include/llvm/CodeGen/DIE.h
index 92265fd86ebb9..6ab1f9c9994f9 100644
--- a/llvm/include/llvm/CodeGen/DIE.h
+++ b/llvm/include/llvm/CodeGen/DIE.h
@@ -547,7 +547,7 @@ struct IntrusiveBackListBase {
 
   void push_back(Node &N) {
     assert(N.Next.getPointer() == &N && "Expected unlinked node");
-    assert(N.Next.getInt() == true && "Expected unlinked node");
+    assert(N.Next.getInt() && "Expected unlinked node");
 
     if (Last) {
       N.Next = Last->Next;
@@ -558,7 +558,7 @@ struct IntrusiveBackListBase {
 
   void push_front(Node &N) {
     assert(N.Next.getPointer() == &N && "Expected unlinked node");
-    assert(N.Next.getInt() == true && "Expected unlinked node");
+    assert(N.Next.getInt() && "Expected unlinked node");
 
     if (Last) {
       N.Next.setPointerAndInt(Last->Next.getPointer(), false);
diff --git a/llvm/include/llvm/Support/DataExtractor.h b/llvm/include/llvm/Support/DataExtractor.h
index ec935e7e10564..72bc1a4afc2a4 100644
--- a/llvm/include/llvm/Support/DataExtractor.h
+++ b/llvm/include/llvm/Support/DataExtractor.h
@@ -37,7 +37,7 @@ inline uint24_t getSwappedBytes(uint24_t C) {
 
 class DataExtractor {
   StringRef Data;
-  uint8_t IsLittleEndian;
+  bool IsLittleEndian;
 
 public:
   /// A class representing a position in a DataExtractor, as well as any error
diff --git a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
index 2f3234683bf55..2df5bcb42b9e0 100644
--- a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp
@@ -915,7 +915,7 @@ bool StubsManager_v7::visitEdge(LinkGraph &G, Block *B, Edge &E) {
     });
   }
 
-  assert(MakeThumb == (StubSymbol->getTargetFlags() & ThumbSymbol) &&
+  assert(MakeThumb == hasTargetFlags(*StubSymbol, ThumbSymbol) &&
          "Instruction set states of stub and relocation site should be equal");
   LLVM_DEBUG({
     dbgs() << "    Using " << (MakeThumb ? "Thumb" : "Arm") << " entry "
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUNextUseAnalysis.cpp b/llvm/lib/Target/AMDGPU/AMDGPUNextUseAnalysis.cpp
index f6fe48bf5bb49..d43363f1a0f85 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUNextUseAnalysis.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUNextUseAnalysis.cpp
@@ -567,7 +567,8 @@ class llvm::AMDGPUNextUseAnalysisImpl {
       const auto &ToInit = R ? ReachablePaths : UnreachablePaths;
       for (const Path &P : ToInit) {
         PathInfo &Slot = getOrInitPathInfo(P.src(), P.dst());
-        assert(Slot.isForwardReachableUnset() || Slot.ForwardReachable == R);
+        assert(Slot.isForwardReachableUnset() ||
+               Slot.ForwardReachable == static_cast<int>(R));
         Slot.ForwardReachable = R;
       }
     }
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 7b5738845ef2c..1bb45253090fc 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -6223,7 +6223,7 @@ bool AMDGPUAsmParser::ParseDirectiveAMDHSAKernel() {
         return Error(IDRange.Start, "directive requires gfx8+", IDRange);
       if (!isUInt<1>(Val))
         return OutOfRangeError(ValRange);
-      if (Val != getTargetStreamer().getTargetID()->isXnackOnOrAny())
+      if ((Val != 0) != getTargetStreamer().getTargetID()->isXnackOnOrAny())
         return getParser().Error(IDRange.Start, ".amdhsa_reserve_xnack_mask does not match target id",
                                  IDRange);
     } else if (ID == ".amdhsa_float_round_mode_32") {
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
index 8c54d292dbd1c..c6976447b508d 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
@@ -1316,7 +1316,7 @@ void AMDGPUInstPrinter::printExpTgt(const MCInst *MI, unsigned OpNo,
 
 static bool allOpsDefaultValue(const int* Ops, int NumOps, int Mod,
                                bool IsPacked, bool HasDstSel) {
-  int DefaultValue = IsPacked && (Mod == SISrcMods::OP_SEL_1);
+  bool DefaultValue = IsPacked && (Mod == SISrcMods::OP_SEL_1);
 
   for (int I = 0; I < NumOps; ++I) {
     if (!!(Ops[I] & Mod) != DefaultValue)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index d3df8a3203d81..989db49085e8c 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -5219,7 +5219,8 @@ static bool isAlternating(const std::array<std::pair<int, int>, 2> &SrcInfo,
     bool C = Src == SrcInfo[1].first && Diff == SrcInfo[1].second;
     assert(C != (Src == SrcInfo[0].first && Diff == SrcInfo[0].second) &&
            "Must match exactly one of the two slides");
-    if (RequiredPolarity != (C == (Idx / Factor) % 2))
+    bool OddGroup = ((Idx / Factor) % 2) != 0;
+    if (RequiredPolarity != (C == OddGroup))
       return false;
   }
   return true;
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index c02ff857cd3eb..42c370c49997a 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -13281,7 +13281,7 @@ struct AANoAliasAddrSpaceImpl : public AANoAliasAddrSpace {
 
   ChangeStatus updateImpl(Attributor &A) override {
     unsigned FlatAS = A.getInfoCache().getFlatAddressSpace().value();
-    uint32_t OldAssumed = getAssumed();
+    bool OldAssumed = getAssumed();
 
     auto CheckAddressSpace = [&](Value &Obj) {
       if (isa<PoisonValue>(&Obj))
diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp
index 2daf2635d96d5..f4cf3ea22d8ff 100644
--- a/mlir/lib/Rewrite/ByteCode.cpp
+++ b/mlir/lib/Rewrite/ByteCode.cpp
@@ -1421,7 +1421,7 @@ void ByteCodeExecutor::executeApplyConstraint(PatternRewriter &rewriter) {
 
   LDBG() << "  * Arguments: " << llvm::interleaved(args);
 
-  ByteCodeField isNegated = read();
+  bool isNegated = read();
   LDBG() << "  * isNegated: " << isNegated;
 
   ByteCodeField numResults = read();



More information about the Mlir-commits mailing list