Skip to content

Conversation

@sedymrak
Copy link
Contributor

When trying to get the SBType object corresponding to the _BitInt(...) type name, we have noticed that the SBTarget::FindFirstType metod returns nil. This branch proposes:

  • some test that demonstrate that the problem exists
  • a possible fix

@llvmbot
Copy link
Member

llvmbot commented Oct 31, 2025

@llvm/pr-subscribers-lldb

Author: Matej Košík (sedymrak)

Changes

When trying to get the SBType object corresponding to the _BitInt(...) type name, we have noticed that the SBTarget::FindFirstType metod returns nil. This branch proposes:

  • some test that demonstrate that the problem exists
  • a possible fix

Full diff: https://github.com/llvm/llvm-project/pull/165857.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+11)
  • (modified) lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py (+20)
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 6ec054d5eac05..cfa936415d634 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5498,6 +5498,17 @@ TypeSystemClang::GetNumChildren(lldb::opaque_compiler_type_t type,
 }
 
 CompilerType TypeSystemClang::GetBuiltinTypeByName(ConstString name) {
+  StringRef name_ref = name.GetStringRef();
+  llvm::Regex re("^(unsigned )?_BitInt\\((.*)\\)$");
+  llvm::SmallVector<llvm::StringRef, 4> matches;
+  bool is_bitint = re.match(name_ref, &matches);
+  if (is_bitint && matches.size() == 3) {
+    bool is_unsigned = matches[1] == "unsigned ";
+    llvm::APInt ap_bit_size;
+    if (!matches[2].getAsInteger(10, ap_bit_size))
+      return GetType(getASTContext().getBitIntType(is_unsigned,
+                                                   ap_bit_size.getZExtValue()));
+  }
   return GetBasicType(GetBasicTypeEnumeration(name));
 }
 
diff --git a/lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py b/lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py
index f8594dfc6b78d..07a4fae82677d 100644
--- a/lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py
+++ b/lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py
@@ -30,9 +30,29 @@ def test(self):
         self.assertEqual(d.GetType().GetBasicType(), int_basic_type)
 
         # Check the size of the chosen basic types.
+        self.assertEqual(self.target().FindFirstType("__int128").name, "__int128")
         self.assertEqual(self.target().FindFirstType("__int128").size, 16)
+        self.assertEqual(
+            self.target().FindFirstType("unsigned __int128").name, "unsigned __int128"
+        )
         self.assertEqual(self.target().FindFirstType("unsigned __int128").size, 16)
 
         # Check the size of the chosen aliases of basic types.
+        self.assertEqual(self.target().FindFirstType("__int128_t").name, "__int128_t")
         self.assertEqual(self.target().FindFirstType("__int128_t").size, 16)
+        self.assertEqual(self.target().FindFirstType("__uint128_t").name, "__uint128_t")
         self.assertEqual(self.target().FindFirstType("__uint128_t").size, 16)
+
+        # "_BitInt(...)" and "unsigned _BitInt(...)" are GNU C compiler extensions
+        # that are supported by LLVM C(++) compiler as well.
+        #
+        # We check that LLDB is able to map the names of these types
+        # (as reported by LLDB for variables of this type)
+        # to the corresponding SBType objects.
+        self.assertEqual(self.target().FindFirstType("_BitInt(65)").name, "_BitInt(65)")
+        self.assertEqual(self.target().FindFirstType("_BitInt(65)").size, 16)
+        self.assertEqual(
+            self.target().FindFirstType("unsigned _BitInt(65)").name,
+            "unsigned _BitInt(65)",
+        )
+        self.assertEqual(self.target().FindFirstType("unsigned _BitInt(65)").size, 16)

@sedymrak sedymrak force-pushed the 2025-10-31-fix-TypeSystemClang-GetBuiltinTypeByName-method branch from 0c91339 to e46d8f3 Compare October 31, 2025 13:06
@sedymrak sedymrak changed the title Make sure that the "TypeSystemClang::GetBuiltinTypeByName" method returns the correct value also for "_BitInt(...)" types. [lldb] Make sure that the "TypeSystemClang::GetBuiltinTypeByName" method returns the correct value also for "_BitInt(...)" types. Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants