[llvm-branch-commits] [clang] PR for llvm/llvm-project#80961 (PR #80962)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Feb 7 01:44:11 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (llvmbot)
<details>
<summary>Changes</summary>
resolves llvm/llvm-project#<!-- -->80961
---
Full diff: https://github.com/llvm/llvm-project/pull/80962.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+4)
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1)
- (modified) clang/test/Sema/warn-int-in-bool-context.c (+11)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b05c72c7f2c3eb..95d44951ae7ee6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -861,6 +861,10 @@ Bug Fixes in This Version
- Fixed assertion failure with deleted overloaded unary operators.
Fixes (`#78314 <https://github.com/llvm/llvm-project/issues/78314>`_)
+- Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
+ for logical operators in C23.
+ Fixes (`#64356 <https://github.com/llvm/llvm-project/issues/64356>`_).
+
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4efcb359035576..0d9c087ed0cd19 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -14062,7 +14062,7 @@ inline QualType Sema::CheckLogicalOperands(ExprResult &LHS, ExprResult &RHS,
Expr::EvalResult EVResult;
if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
llvm::APSInt Result = EVResult.Val.getInt();
- if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
+ if ((getLangOpts().CPlusPlus && !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
(Result != 0 && Result != 1)) {
Diag(Loc, diag::warn_logical_instead_of_bitwise)
diff --git a/clang/test/Sema/warn-int-in-bool-context.c b/clang/test/Sema/warn-int-in-bool-context.c
index 0c94ebb391f3c5..99f3db9f8d41a7 100644
--- a/clang/test/Sema/warn-int-in-bool-context.c
+++ b/clang/test/Sema/warn-int-in-bool-context.c
@@ -72,3 +72,14 @@ int test(int a, unsigned b, enum num n) {
// Don't warn in macros.
return SHIFT(1, a);
}
+
+int GH64356(int arg) {
+ if ((arg == 1) && (1 == 1)) return 1;
+ return 0;
+
+ if ((64 > 32) && (32 < 64))
+ return 2;
+
+ if ((1 == 1) && (arg == 1)) return 1;
+ return 0;
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/80962
More information about the llvm-branch-commits
mailing list