[clang] [clang][NFC] Fix the static assertion in 4797437 (PR #120643)
Ziqing Luo via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 19 13:54:00 PST 2024
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/120643
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.
>From 127c7592c480f4730f2cd7e49e272fff64f7a65d Mon Sep 17 00:00:00 2001
From: Ziqing Luo <ziqing_luo at apple.com>
Date: Thu, 19 Dec 2024 13:44:42 -0800
Subject: [PATCH] [clang][NFC] Fix the static assertion in 4797437
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.
---
clang/include/clang/AST/Stmt.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
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"
More information about the cfe-commits
mailing list