[clang] [libclang] Add clang_Type_getDependentSizeExpr (PR #212648)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 30 06:21:46 PDT 2026
https://github.com/w-utter updated https://github.com/llvm/llvm-project/pull/212648
>From ded00301e58cb228a318e0c008bdcd33a4c836c7 Mon Sep 17 00:00:00 2001
From: will <104373134+w-utter at users.noreply.github.com>
Date: Wed, 29 Jul 2026 08:52:56 +1000
Subject: [PATCH] [libclang] Add clang_Type_getDependentSizeExpr
---
clang/include/clang-c/Index.h | 8 ++++++++
clang/tools/libclang/CXType.cpp | 26 ++++++++++++++++++++++++++
clang/tools/libclang/libclang.map | 1 +
3 files changed, 35 insertions(+)
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 8427236e0b444..3c2ae30d9bbb9 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3734,6 +3734,14 @@ CINDEX_LINKAGE CXType clang_Type_getModifiedType(CXType T);
*/
CINDEX_LINKAGE CXType clang_Type_getValueType(CXType CT);
+
+/**
+ * Gets the expression associated with this dependent sized array
+ *
+ * If a non-dependent type is passed in, an invalid cursor is returned.
+ */
+CINDEX_LINKAGE CXCursor clang_Type_getDependentSizeExpr(CXType CT);
+
/**
* Return the offset of the field represented by the Cursor.
*
diff --git a/clang/tools/libclang/CXType.cpp b/clang/tools/libclang/CXType.cpp
index 0063939dec423..52e813ea3c795 100644
--- a/clang/tools/libclang/CXType.cpp
+++ b/clang/tools/libclang/CXType.cpp
@@ -912,6 +912,32 @@ long long clang_getNumElements(CXType CT) {
return result;
}
+CXCursor clang_Type_getDependentSizeExpr(CXType CT) {
+ QualType T = GetQualType(CT);
+ const Type *TP = T.getTypePtrOrNull();
+
+ if (!TP)
+ return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
+
+ const Expr* E = nullptr;
+
+ switch (TP->getTypeClass()) {
+ case Type::DependentSizedArray:
+ E = cast<DependentSizedArrayType> (TP)->getSizeExpr();
+ break;
+ case Type::DependentSizedExtVector:
+ E = cast<DependentSizedExtVectorType> (TP)->getSizeExpr();
+ break;
+ default:
+ break;
+ }
+
+ if (!E)
+ return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
+
+ return cxcursor::MakeCXCursor(E, nullptr, GetTU(CT));
+}
+
CXType clang_getArrayElementType(CXType CT) {
QualType ET = QualType();
QualType T = GetQualType(CT);
diff --git a/clang/tools/libclang/libclang.map b/clang/tools/libclang/libclang.map
index 57f281096929d..4864cb6da5929 100644
--- a/clang/tools/libclang/libclang.map
+++ b/clang/tools/libclang/libclang.map
@@ -461,6 +461,7 @@ LLVM_23 {
global:
clang_ModuleCache_prune;
clang_ModuleCache_pruneWithCallback;
+ clang_Type_getDependentSizeExpr;
};
# Example of how to add a new symbol version entry. If you do add a new symbol
More information about the cfe-commits
mailing list