-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
-Wconstant-logical-operand regression with comparison operators in C2x mode with Clang 17 #64356
Comments
@llvm/issue-subscribers-clang-frontend |
@llvm/issue-subscribers-c2x |
This isn't a regression, it's an intentional improvement to the diagnostic made in https://reviews.llvm.org/D142609 The reason why C23 and C17 modes are different is because of this: llvm-project/clang/lib/Sema/SemaExpr.cpp Line 13910 in 9f72df7
In C23, CC @xgupta |
I was identifying this as a regression only because the purpose of e.g. that improvement is about handling |
Hmm, I don't think I had picked up on that distinction. To me, this diagnostic is when you have logical operands with a constant on one side. Sometimes that's because the intent was to perform a bitwise operation ( CC @cjdb @jyknight @efriedma-quic @rjmccall for opinions on whether we should roll back the changes from https://reviews.llvm.org/D142609 because they're taking the diagnostic in an unintended direction. |
Although a tautology, I support the roll back. |
ok2revert |
Well "true || something something)" case is exactly the case where I would like to see some warning, because it may be the case that you are debugging something, you put "true ||" part as a hack and you forget about it and booom, bug. |
I would expect that to be a different warning. That wouldn't fire here since this diagnostic is specifically targeting integer constants involved in Also for the warning you're asking for, But regardless, this warning doesn't fire for actual I think the proper slightly longer-term fix would to re-land this warning exactly the same but to treat the results of comparison operators as being booleans for the purpose of this diagnostic, even though they're actually integers. |
C23 has bool, but logical operators still return int. Double check that we're not in C23 to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356
Even though changes from https://reviews.llvm.org/D142609 were reverted, the problem still exists. D142609 only made check for both operands, not only the left one. So If I do
https://godbolt.org/z/88srzhEb5 llvm-project/clang/lib/Sema/SemaExpr.cpp Line 14076 in dd70aef
But since as @AaronBallman mentioned C's logical operators return int and not bool, even in C23, this check should be modified to avoid this false positive warning and the one reported in #80548 . |
The behavior of this warning clearly should not differ in C17 and C23 just because the result of |
The changes in #80724 reflect that. |
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes #64356
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
C23 has `bool`, but logical operators still return int. Check that we're not in C to avoid false-positive -Wconstant-logical-operand. Fixes llvm#64356 (cherry picked from commit a18e92d)
Basic programs involving constant comparisons produce
-Wconstant-logical-operand
with-std=c2x
but not with-std=c17
.This program shouldn't produced
-Wconstant-logical-operand
because my understanding is that's for using boolean operations with integer operands, but these should both be booleans.This is happening only in trunk and the clang 17 release, neither one produces the warning in clang 16.
(This program is reduced from a program with a constant
sizeof
comparison that was failing.)Godbolt link demonstrating the regression: https://godbolt.org/z/e15rEc6r9
The text was updated successfully, but these errors were encountered: