Skip to content

Commit fd4399c

Browse files
authored
[lldb] Fix crash in SymbolFileCTF::ParseFunctions (llvm#89845)
Make SymbolFileCTF::ParseFunctions resilient against not being able to resolve the argument or return type of a function. ResolveTypeUID can fail for a variety of reasons so we should always check its result. The type that caused the crash was `_Bool` which we didn't recognize as a basic type. This commit also fixes the underlying issue and adds a test. rdar://126943722
1 parent 3fa6b9c commit fd4399c

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ SymbolFileCTF::CreateInteger(const CTFInteger &ctf_integer) {
342342

343343
CompilerType compiler_type = m_ast->GetBasicType(basic_type);
344344

345-
if (basic_type != eBasicTypeVoid) {
345+
if (basic_type != eBasicTypeVoid && basic_type != eBasicTypeBool) {
346346
// Make sure the type we got is an integer type.
347347
bool compiler_type_is_signed = false;
348348
if (!compiler_type.IsIntegerType(compiler_type_is_signed))
@@ -802,7 +802,8 @@ size_t SymbolFileCTF::ParseFunctions(CompileUnit &cu) {
802802
}
803803

804804
Type *arg_type = ResolveTypeUID(arg_uid);
805-
arg_types.push_back(arg_type->GetFullCompilerType());
805+
arg_types.push_back(arg_type ? arg_type->GetFullCompilerType()
806+
: CompilerType());
806807
}
807808

808809
if (symbol) {
@@ -813,8 +814,9 @@ size_t SymbolFileCTF::ParseFunctions(CompileUnit &cu) {
813814

814815
// Create function type.
815816
CompilerType func_type = m_ast->CreateFunctionType(
816-
ret_type->GetFullCompilerType(), arg_types.data(), arg_types.size(),
817-
is_variadic, 0, clang::CallingConv::CC_C);
817+
ret_type ? ret_type->GetFullCompilerType() : CompilerType(),
818+
arg_types.data(), arg_types.size(), is_variadic, 0,
819+
clang::CallingConv::CC_C);
818820
lldb::user_id_t function_type_uid = m_types.size() + 1;
819821
TypeSP type_sp =
820822
MakeType(function_type_uid, symbol->GetName(), 0, nullptr,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,11 @@ lldb::BasicType TypeSystemClang::GetBasicTypeEnumeration(llvm::StringRef name) {
838838
{"__int128_t", eBasicTypeInt128},
839839
{"__uint128_t", eBasicTypeUnsignedInt128},
840840

841-
// Miscellaneous
841+
// "bool"
842842
{"bool", eBasicTypeBool},
843+
{"_Bool", eBasicTypeBool},
844+
845+
// Miscellaneous
843846
{"float", eBasicTypeFloat},
844847
{"double", eBasicTypeDouble},
845848
{"long double", eBasicTypeLongDouble},

lldb/test/API/macosx/ctf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MAKE_DSYM := YES
44
ifeq "$(COMPRESS_CTF)" "YES"
55
COMPRESS := -c
66
else
7-
COMPRESS :=
7+
COMPRESS :=
88
endif
99

1010
all: a.out a.ctf

lldb/test/API/macosx/ctf/TestCTF.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def do_test(self):
5353
"[2] = 'b'",
5454
"[3] = 'c'",
5555
'u = (i = 1, s = "")',
56+
"b = false",
5657
"f = 0x0000000000000000",
5758
],
5859
)

lldb/test/API/macosx/ctf/test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdbool.h>
12
#include <stdio.h>
23

34
struct ForwardDecl;
@@ -24,6 +25,7 @@ typedef struct MyNestedStruct {
2425
char a[4];
2526
MyEnumT e;
2627
MyUnionT u;
28+
_Bool b;
2729
} MyNestedStructT;
2830

2931
typedef struct MyStruct {
@@ -54,6 +56,7 @@ void populate(MyInt i) {
5456
foo.n.a[2] = 'c';
5557
foo.n.a[3] = 'd';
5658
foo.n.e = eOne;
59+
foo.n.b = false;
5760
foo.f = NULL;
5861
forward = NULL;
5962
bar.b = i;

0 commit comments

Comments
 (0)