[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 19 13:54:32 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Ziqing Luo (ziqingluo-90)

<details>
<summary>Changes</summary>

In the previous commit 4797437463e63ee289a1ff1904cfb7b2fe6cb4c2, 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.

---
Full diff: https://github.com/llvm/llvm-project/pull/120643.diff


1 Files Affected:

- (modified) clang/include/clang/AST/Stmt.h (+4-4) 


``````````diff
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"
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/120643


More information about the cfe-commits mailing list