[Lldb-commits] [lldb] 320e025 - [lldb] Add GetPointerDiffType to TypeSystemClang (#185314)

via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 10 04:06:58 PDT 2026


Author: Ilia Kuklin
Date: 2026-03-10T16:06:53+05:00
New Revision: 320e025b596598c93c4c2bceec6e9e2ff307bcd5

URL: https://github.com/llvm/llvm-project/commit/320e025b596598c93c4c2bceec6e9e2ff307bcd5
DIFF: https://github.com/llvm/llvm-project/commit/320e025b596598c93c4c2bceec6e9e2ff307bcd5.diff

LOG: [lldb] Add GetPointerDiffType to TypeSystemClang (#185314)

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 d7f4cfcf0ffc7..8ee7df40051bc 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -221,6 +221,8 @@ class TypeSystem : public PluginInterface,
 
   virtual uint32_t GetPointerByteSize() = 0;
 
+  virtual CompilerType GetPointerDiffType(bool is_signed) = 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 0984d4d7190e7..211630f24c7f4 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2401,6 +2401,16 @@ CompilerType TypeSystemClang::GetPointerSizedIntType(bool is_signed) {
       getASTContext().getTypeSize(getASTContext().VoidPtrTy), is_signed);
 }
 
+CompilerType TypeSystemClang::GetPointerDiffType(bool is_signed) {
+  // Check if builtin types are initialized.
+  if (!getASTContext().VoidPtrTy)
+    return {};
+
+  if (is_signed)
+    return GetType(getASTContext().getPointerDiffType());
+  return GetType(getASTContext().getUnsignedPointerDiffType());
+}
+
 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 aac1b5966f90c..e2c63741c82f8 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -510,6 +510,8 @@ class TypeSystemClang : public TypeSystem {
 
   CompilerType GetPointerSizedIntType(bool is_signed);
 
+  CompilerType GetPointerDiffType(bool is_signed) 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 76abdd12d32a6..d8d95f17e5104 100644
--- a/lldb/unittests/Symbol/TestTypeSystemClang.cpp
+++ b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
@@ -348,6 +348,8 @@ TEST_F(TestTypeSystemClang, TestBuiltinTypeForEmptyTriple) {
                    .IsValid());
   EXPECT_FALSE(ast.GetPointerSizedIntType(/*is_signed=*/false));
   EXPECT_FALSE(ast.GetIntTypeFromBitSize(8, /*is_signed=*/false));
+  EXPECT_FALSE(ast.GetPointerDiffType(/*is_signed=*/true));
+  EXPECT_FALSE(ast.GetPointerDiffType(/*is_signed=*/false));
 
   CompilerType record_type =
       ast.CreateRecordType(nullptr, OptionalClangModuleID(), "Record",
@@ -360,6 +362,21 @@ TEST_F(TestTypeSystemClang, TestBuiltinTypeForEmptyTriple) {
   TypeSystemClang::CompleteTagDeclarationDefinition(record_type);
 }
 
+TEST_F(TestTypeSystemClang, TestGetPointerDiffType) {
+  CompilerType ptr
diff _t = m_ast->GetPointerDiffType(/*is_signed=*/true);
+  EXPECT_EQ(ptr
diff _t.GetDisplayTypeName(), "__ptr
diff _t");
+  EXPECT_TRUE(ptr
diff _t.IsSigned());
+  EXPECT_EQ(
+      llvm::expectedToOptional(ptr
diff _t.GetByteSize(nullptr)).value_or(0),
+      m_ast->GetPointerByteSize());
+
+  CompilerType uptr
diff _t = m_ast->GetPointerDiffType(/*is_signed=*/false);
+  EXPECT_FALSE(uptr
diff _t.IsSigned());
+  EXPECT_EQ(
+      llvm::expectedToOptional(uptr
diff _t.GetByteSize(nullptr)).value_or(0),
+      m_ast->GetPointerByteSize());
+}
+
 TEST_F(TestTypeSystemClang, TestGetBuiltinTypeByName_BitInt) {
   auto holder =
       std::make_unique<clang_utils::TypeSystemClangHolder>("bitint_ast");


        


More information about the lldb-commits mailing list