Author: Matej Košík
Date: 2026-01-13T09:03:49Z
New Revision: 8aa9c717f6bf6a8844c109742d520805c50003ab

URL: 
https://github.com/llvm/llvm-project/commit/8aa9c717f6bf6a8844c109742d520805c50003ab
DIFF: 
https://github.com/llvm/llvm-project/commit/8aa9c717f6bf6a8844c109742d520805c50003ab.diff

LOG: [lldb] Make sure that the "TypeSystemClang::GetBuiltinTypeByName" method 
returns the correct value also for "_BitInt(...)" types. (#165857)

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

---------

Co-authored-by: Matej Košík <[email protected]>
Co-authored-by: Michael Buch <[email protected]>

Added: 
    

Modified: 
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index b70b1bf4b4aac..06f886b7e3438 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5505,6 +5505,21 @@ 
TypeSystemClang::GetNumChildren(lldb::opaque_compiler_type_t type,
 }
 
 CompilerType TypeSystemClang::GetBuiltinTypeByName(ConstString name) {
+  StringRef name_ref = name.GetStringRef();
+  // We compile the regex only the type name fulfills certain
+  // necessary conditions. Otherwise we do not bother.
+  if (name_ref.consume_front("unsigned _BitInt(") ||
+      name_ref.consume_front("_BitInt(")) {
+    uint64_t bit_size;
+    if (name_ref.consumeInteger(/*Radix=*/10, bit_size))
+      return {};
+
+    if (!name_ref.consume_front(")"))
+      return {};
+
+    return GetType(getASTContext().getBitIntType(
+        name.GetStringRef().starts_with("unsigned"), bit_size));
+  }
   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..784f3e177d970 100644
--- a/lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py
+++ b/lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py
@@ -36,3 +36,19 @@ def test(self):
         # Check the size of the chosen aliases of basic types.
         self.assertEqual(self.target().FindFirstType("__int128_t").size, 16)
         self.assertEqual(self.target().FindFirstType("__uint128_t").size, 16)
+
+        self.assertFalse(self.target().FindFirstType("_BitInt"))
+        self.assertFalse(self.target().FindFirstType("unsigned _BitInt"))
+        self.assertFalse(self.target().FindFirstType("_BitInt()"))
+        self.assertFalse(self.target().FindFirstType("unsigned _BitInt()"))
+        self.assertFalse(self.target().FindFirstType("_BitInt(65"))
+        self.assertFalse(self.target().FindFirstType("unsigned _BitInt(65"))
+        self.assertFalse(self.target().FindFirstType("_BitInt(0x41)"))
+        self.assertFalse(self.target().FindFirstType("unsigned _BitInt(0x41)"))
+        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)


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

Reply via email to