-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][NFC] Fix the static assertion in 4797437 #120643
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
@llvm/pr-subscribers-clang Author: Ziqing Luo (ziqingluo-90) ChangesIn the previous commit 4797437, I used Full diff: https://github.com/llvm/llvm-project/pull/120643.diff 1 Files Affected:
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 07cb63956aed0d..ef6824199b0af0 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -114,10 +114,10 @@ class alignas(void *) Stmt {
#define STMT(CLASS, PARENT)
#define STMT_RANGE(BASE, FIRST, LAST)
#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
- static_assert( \
- llvm::isInt<NumStmtBits>(StmtClass::LAST##Class), \
- "The number of 'StmtClass'es is strictly bounded under two to " \
- "the power of 'NumStmtBits'");
+ static_assert(0 <= StmtClass::LAST##Class && \
+ StmtClass::LAST##Class < (INT64_C(1) << NumStmtBits), \
+ "The number of 'StmtClass'es is strictly bound by a bitfield " \
+ "of width NumStmtBits");
#define ABSTRACT_STMT(STMT)
#include "clang/AST/StmtNodes.inc"
|
127c759
to
b057ae3
Compare
dd71be8
to
d1b45d1
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
In the previous commit 4797437, I used `llvm::isInt<NumStmtBits>(StmtClass::LAST##Class)` to test if `StmtClass` is strictly bounded by the an unsigned integer of 'NumStmtBits'. That is incorrect as `llvm::isInt` tests for signed integers. This commit fixes it.
d1b45d1
to
ada689a
Compare
may as well address @nikic's post-commit suggestion to move this out of the header, and into a source file, while you're here: #120341 (comment) |
oops, I saw this after I hit the merge button. I will do it in a follow-up commit. |
…urce A follow-up change to PR #120341 & #120643. Address @nikic's concern: #120341 (comment)
In the previous commit 4797437, I used
llvm::isInt<NumStmtBits>(StmtClass::LAST##Class)
to test ifStmtClass
is strictly bounded by the an unsigned integer of 'NumStmtBits'. That is incorrect asllvm::isInt
tests for signed integers. This commit fixes it.