Skip to content

Commit 9594a7e

Browse files
sedymrakMatej Košík
authored andcommitted
[lldb] Fix TypeSystemClang::GetBasicTypeEnumeration for 128-bit int types (llvm#162278)
When we take the following C program: ``` int main() { return 0; } ``` and create a statically-linked executable from it: ``` clang -static -g -o main main.c ``` Then we can observe the following `lldb` behavior: ``` $ lldb (lldb) target create main Current executable set to '.../main' (x86_64). (lldb) breakpoint set --name main Breakpoint 1: where = main`main + 11 at main.c:2:3, address = 0x000000000022aa7b (lldb) process launch Process 3773637 launched: '/home/me/tmp/built-in/main' (x86_64) Process 3773637 stopped * thread llvm#1, name = 'main', stop reason = breakpoint 1.1 frame #0: 0x000000000022aa7b main`main at main.c:2:3 1 int main() { -> 2 return 0; 3 } (lldb) script lldb.debugger.GetSelectedTarget().FindFirstType("__int128").size 0 (lldb) script lldb.debugger.GetSelectedTarget().FindFirstType("unsigned __int128").size 0 (lldb) quit ``` The value return by the `SBTarget::FindFirstType` method is wrong for the `__int128` and `unsigned __int128` basic types. The proposed changes make the `TypeSystemClang::GetBasicTypeEnumeration` method consistent with `gcc` and `clang` C [language extension](https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html) related to 128-bit integer types as well as with the `BuiltinType::getName` method in the LLVM codebase itself. When the above change is applied, the behavior of the `lldb` changes in the following (desired) way: ``` $ lldb (lldb) target create main Current executable set to '.../main' (x86_64). (lldb) breakpoint set --name main Breakpoint 1: where = main`main + 11 at main.c:2:3, address = 0x000000000022aa7b (lldb) process launch Process 3773637 launched: '/home/me/tmp/built-in/main' (x86_64) Process 3773637 stopped * thread llvm#1, name = 'main', stop reason = breakpoint 1.1 frame #0: 0x000000000022aa7b main`main at main.c:2:3 1 int main() { -> 2 return 0; 3 } (lldb) script lldb.debugger.GetSelectedTarget().FindFirstType("__int128").size 16 (lldb) script lldb.debugger.GetSelectedTarget().FindFirstType("unsigned __int128").size 16 (lldb) quit ``` --------- Co-authored-by: Matej Košík <[email protected]>
1 parent a578a12 commit 9594a7e

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,20 @@ lldb::BasicType TypeSystemClang::GetBasicTypeEnumeration(llvm::StringRef name) {
849849
{"unsigned long long int", eBasicTypeUnsignedLongLong},
850850

851851
// "int128"
852+
//
853+
// The following two lines are here only
854+
// for the sake of backward-compatibility.
855+
// Neither "__int128_t", nor "__uint128_t" are basic-types.
856+
// They are typedefs.
852857
{"__int128_t", eBasicTypeInt128},
853858
{"__uint128_t", eBasicTypeUnsignedInt128},
859+
// In order to be consistent with:
860+
// - gcc's C programming language extension related to 128-bit integers
861+
// https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html
862+
// - the "BuiltinType::getName" method in LLVM
863+
// the following two lines must be present:
864+
{"__int128", eBasicTypeInt128},
865+
{"unsigned __int128", eBasicTypeUnsignedInt128},
854866

855867
// "bool"
856868
{"bool", eBasicTypeBool},

lldb/test/API/python_api/sbtype_basic_type/TestSBTypeBasicType.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ def test(self):
2828
self.assertEqual(b.GetType().GetBasicType(), int_basic_type)
2929
self.assertEqual(c.GetType().GetBasicType(), int_basic_type)
3030
self.assertEqual(d.GetType().GetBasicType(), int_basic_type)
31+
32+
# Check the size of the chosen basic types.
33+
self.assertEqual(self.target().FindFirstType("__int128").size, 16)
34+
self.assertEqual(self.target().FindFirstType("unsigned __int128").size, 16)
35+
36+
# Check the size of the chosen aliases of basic types.
37+
self.assertEqual(self.target().FindFirstType("__int128_t").size, 16)
38+
self.assertEqual(self.target().FindFirstType("__uint128_t").size, 16)

lldb/unittests/Symbol/TestTypeSystemClang.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ TEST_F(TestTypeSystemClang, TestGetBasicTypeFromName) {
162162
EXPECT_EQ(GetBasicQualType(eBasicTypeInt128), GetBasicQualType("__int128_t"));
163163
EXPECT_EQ(GetBasicQualType(eBasicTypeUnsignedInt128),
164164
GetBasicQualType("__uint128_t"));
165+
EXPECT_EQ(GetBasicQualType(eBasicTypeInt128), GetBasicQualType("__int128"));
166+
EXPECT_EQ(GetBasicQualType(eBasicTypeUnsignedInt128),
167+
GetBasicQualType("unsigned __int128"));
165168
EXPECT_EQ(GetBasicQualType(eBasicTypeVoid), GetBasicQualType("void"));
166169
EXPECT_EQ(GetBasicQualType(eBasicTypeBool), GetBasicQualType("bool"));
167170
EXPECT_EQ(GetBasicQualType(eBasicTypeFloat), GetBasicQualType("float"));

0 commit comments

Comments
 (0)