Author: Ilia Kuklin
Date: 2026-08-11T19:16:25+05:00
New Revision: 458db8a1f88e23a313be1d0d5f6826dd0f1621bf

URL: 
https://github.com/llvm/llvm-project/commit/458db8a1f88e23a313be1d0d5f6826dd0f1621bf
DIFF: 
https://github.com/llvm/llvm-project/commit/458db8a1f88e23a313be1d0d5f6826dd0f1621bf.diff

LOG: [lldb] Add GetSizeType to TypeSystemClang to retrieve `size_t` (#211654)

This will be used to implement operator `sizeof` for DIL.

Added: 
    

Modified: 
    lldb/include/lldb/Symbol/TypeSystem.h
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
    lldb/unittests/Symbol/TestTypeSystemClang.cpp

Removed: 
    


################################################################################
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 51258568136bc..51018c1922c4d 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");


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to