[Lldb-commits] [lldb] [lldb] Add GetPointerDiffType to TypeSystemClang (PR #185314)
via lldb-commits
lldb-commits at lists.llvm.org
Sun Mar 8 12:13:57 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Ilia Kuklin (kuilpd)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/185314.diff
4 Files Affected:
- (modified) lldb/include/lldb/Symbol/TypeSystem.h (+2)
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+9)
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h (+2)
- (modified) lldb/unittests/Symbol/TestTypeSystemClang.cpp (+13)
``````````diff
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..514f4c5f21d11 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2401,6 +2401,15 @@ CompilerType TypeSystemClang::GetPointerSizedIntType(bool is_signed) {
getASTContext().getTypeSize(getASTContext().VoidPtrTy), is_signed);
}
+CompilerType TypeSystemClang::GetPointerDiffType(bool is_signed) {
+ 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..6911f02f4387e 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,17 @@ TEST_F(TestTypeSystemClang, TestBuiltinTypeForEmptyTriple) {
TypeSystemClang::CompleteTagDeclarationDefinition(record_type);
}
+TEST_F(TestTypeSystemClang, TestGetPointerDiffType) {
+ CompilerType ptrdiff_t = m_ast->GetPointerDiffType(/*is_signed=*/true);
+ EXPECT_EQ(ptrdiff_t.GetDisplayTypeName(), "__ptrdiff_t");
+
+ CompilerType uptrdiff_t = m_ast->GetPointerDiffType(/*is_signed=*/false);
+ EXPECT_FALSE(uptrdiff_t.IsSigned());
+ EXPECT_EQ(
+ llvm::expectedToOptional(uptrdiff_t.GetByteSize(nullptr)).value_or(0),
+ m_ast->GetPointerByteSize());
+}
+
TEST_F(TestTypeSystemClang, TestGetBuiltinTypeByName_BitInt) {
auto holder =
std::make_unique<clang_utils::TypeSystemClangHolder>("bitint_ast");
``````````
</details>
https://github.com/llvm/llvm-project/pull/185314
More information about the lldb-commits
mailing list