-
Notifications
You must be signed in to change notification settings - Fork 15k
[NFC] Fix Parens on assertion from 147514 #158635
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
Conversation
As brought up on the review for llvm#147514, the original patch doesn't correctly parenthesize the expression in the assert. This fixes it.
|
@llvm/pr-subscribers-clang Author: Erich Keane (erichkeane) ChangesAs brought up on the review for #147514, the original patch doesn't correctly parenthesize the expression in the assert. This fixes it. Full diff: https://github.com/llvm/llvm-project/pull/158635.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index ce483c5cc4e45..4fa25c5d66669 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2142,9 +2142,9 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
bool Ignore = TestAndClearIgnoreResultAssign();
(void)Ignore;
unsigned NumInitElements = E->getNumInits();
- assert(Ignore == false ||
- (NumInitElements == 0 && E->getType()->isVoidType()) &&
- "init list ignored");
+ assert((Ignore == false ||
+ (NumInitElements == 0 && E->getType()->isVoidType())) &&
+ "init list ignored");
// HLSL initialization lists in the AST are an expansion which can contain
// side-effecting expressions wrapped in opaque value expressions. To properly
|
|
@llvm/pr-subscribers-clang-codegen Author: Erich Keane (erichkeane) ChangesAs brought up on the review for #147514, the original patch doesn't correctly parenthesize the expression in the assert. This fixes it. Full diff: https://github.com/llvm/llvm-project/pull/158635.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index ce483c5cc4e45..4fa25c5d66669 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2142,9 +2142,9 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
bool Ignore = TestAndClearIgnoreResultAssign();
(void)Ignore;
unsigned NumInitElements = E->getNumInits();
- assert(Ignore == false ||
- (NumInitElements == 0 && E->getType()->isVoidType()) &&
- "init list ignored");
+ assert((Ignore == false ||
+ (NumInitElements == 0 && E->getType()->isVoidType())) &&
+ "init list ignored");
// HLSL initialization lists in the AST are an expansion which can contain
// side-effecting expressions wrapped in opaque value expressions. To properly
|
|
Thanks for picking this up! |
| assert((Ignore == false || | ||
| (NumInitElements == 0 && E->getType()->isVoidType())) && | ||
| "init list ignored"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following alternative is perhaps more clear, and allows to remove the (void)Ignore line from just above.
| assert((Ignore == false || | |
| (NumInitElements == 0 && E->getType()->isVoidType())) && | |
| "init list ignored"); | |
| if (Ignore) | |
| assert(NumInitElements == 0 && E->getType()->isVoidType() | |
| && "only ignore irrelevant init list"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That version ends up having a weird dead branch in non-asserts builds, and is problematic as assert is a macro. I don't see the losing the cast as worth the additional risk/breaking up the purpose of the assert here, so I'm going to leave it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, good to me. The extra parentheses solve the GCC warning.
As brought up on the review for #147514, the original patch doesn't correctly parenthesize the expression in the assert. This fixes it.