[Lldb-commits] [lldb] [lldb] Add GetSizeType to TypeSystemClang to retrieve `size_t` (PR #211654)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 7 05:49:41 PDT 2026
https://github.com/kuilpd updated https://github.com/llvm/llvm-project/pull/211654
>From 17b40e4ca2ef6046ad0e5427dd6b1e1528caa583 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Fri, 24 Jul 2026 00:30:27 +0500
Subject: [PATCH] [lldb] Add GetSizeType `size_t` to TypeSystemClang
---
lldb/include/lldb/Symbol/TypeSystem.h | 2 ++
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 8 ++++++++
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h | 2 ++
lldb/unittests/Symbol/TestTypeSystemClang.cpp | 7 +++++++
4 files changed, 19 insertions(+)
diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index 1fa9d4ba26cfe..9ec0f13814975 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -227,6 +227,8 @@ class TypeSystem : public PluginInterface,
virtual CompilerType GetPointerDiffType(bool is_signed) = 0;
+ virtual CompilerType GetSizeType() = 0;
+
virtual unsigned GetPtrAuthKey(lldb::opaque_compiler_type_t type) = 0;
virtual unsigned
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 4a637f0817759..8a14a3d16667c 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2414,6 +2414,14 @@ CompilerType TypeSystemClang::GetPointerDiffType(bool is_signed) {
return GetType(getASTContext().getUnsignedPointerDiffType());
}
+CompilerType TypeSystemClang::GetSizeType() {
+ // Check if builtin types are initialized.
+ if (!getASTContext().VoidPtrTy)
+ return {};
+
+ return GetType(getASTContext().getSizeType());
+}
+
void TypeSystemClang::DumpDeclContextHiearchy(clang::DeclContext *decl_ctx) {
if (decl_ctx) {
DumpDeclContextHiearchy(decl_ctx->getParent());
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 59805085873fe..28e79f2b0b11f 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -512,6 +512,8 @@ class TypeSystemClang : public TypeSystem {
CompilerType GetPointerDiffType(bool is_signed) override;
+ CompilerType GetSizeType() override;
+
// Floating point functions
static CompilerType GetFloatTypeFromBitSize(clang::ASTContext *ast,
diff --git a/lldb/unittests/Symbol/TestTypeSystemClang.cpp b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
index 2b5c8f6e14048..314f8e2c97e19 100644
--- a/lldb/unittests/Symbol/TestTypeSystemClang.cpp
+++ b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
@@ -349,6 +349,7 @@ TEST_F(TestTypeSystemClang, TestBuiltinTypeForEmptyTriple) {
EXPECT_FALSE(ast.GetIntTypeFromBitSize(8, /*is_signed=*/false));
EXPECT_FALSE(ast.GetPointerDiffType(/*is_signed=*/true));
EXPECT_FALSE(ast.GetPointerDiffType(/*is_signed=*/false));
+ EXPECT_FALSE(ast.GetSizeType());
CompilerType record_type =
ast.CreateRecordType(nullptr, OptionalClangModuleID(), "Record",
@@ -376,6 +377,12 @@ TEST_F(TestTypeSystemClang, TestGetPointerDiffType) {
m_ast->GetPointerByteSize());
}
+TEST_F(TestTypeSystemClang, TestGetSizeType) {
+ CompilerType size_type = m_ast->GetSizeType();
+ EXPECT_EQ(size_type.GetDisplayTypeName(), "__size_t");
+ EXPECT_FALSE(size_type.IsSigned());
+}
+
TEST_F(TestTypeSystemClang, TestGetBuiltinTypeByName_BitInt) {
auto holder =
std::make_unique<clang_utils::TypeSystemClangHolder>("bitint_ast");
More information about the lldb-commits
mailing list