[clang] [clang][AST] Clean up AST element count functions (PR #215456)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 22:06:56 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/215456
Make them static and clarify documentation.
>From d5fb6c3607cddaf495d31ac652ad260a29218c73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 11 Aug 2026 07:04:16 +0200
Subject: [PATCH] [clang][AST] Clean up AST element count functions
Make them static and clarify documentation.
---
clang/include/clang/AST/ASTContext.h | 14 ++++++++------
clang/lib/AST/ASTContext.cpp | 12 +++++-------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index bd4dd2ad06aac..43099d546159f 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3229,12 +3229,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
/// actually be an array type).
QualType getBaseElementType(QualType QT) const;
- /// Return number of constant array elements.
- uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
-
- /// Return number of elements initialized in an ArrayInitLoopExpr.
- uint64_t
- getArrayInitLoopExprElementCount(const ArrayInitLoopExpr *AILE) const;
+ /// Return number of (potentially nested) constant array elements.
+ static uint64_t getConstantArrayElementCount(const ConstantArrayType *CA);
+
+ /// Return number of elements initialized in a (potentially nested)
+ /// ArrayInitLoopExpr.
+ /// \c AILE may be null, in which case 0 is returned.
+ static uint64_t
+ getArrayInitLoopExprElementCount(const ArrayInitLoopExpr *AILE);
/// Perform adjustment on the parameter type of a function.
///
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5539a39d6edaf..4838fbba1100e 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8228,20 +8228,18 @@ QualType ASTContext::getBaseElementType(QualType type) const {
return getQualifiedType(type, qs);
}
-/// getConstantArrayElementCount - Returns number of constant array elements.
-uint64_t
-ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const {
+uint64_t ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) {
uint64_t ElementCount = 1;
do {
ElementCount *= CA->getZExtSize();
- CA = dyn_cast_or_null<ConstantArrayType>(
- CA->getElementType()->getAsArrayTypeUnsafe());
+ CA = dyn_cast_if_present<ConstantArrayType>(
+ CA->getElementType()->getAsArrayTypeUnsafe());
} while (CA);
return ElementCount;
}
-uint64_t ASTContext::getArrayInitLoopExprElementCount(
- const ArrayInitLoopExpr *AILE) const {
+uint64_t
+ASTContext::getArrayInitLoopExprElementCount(const ArrayInitLoopExpr *AILE) {
if (!AILE)
return 0;
More information about the cfe-commits
mailing list