Skip to content

[lldb][TypeSystem][NFC] CreateFunctionType to take parameters by llvm::ArrayRef #142620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1978,10 +1978,10 @@ void ClangExpressionDeclMap::AddContextClassType(NameSearchContext &context,
copied_clang_type.GetCompleteType()) {
CompilerType void_clang_type =
m_clang_ast_context->GetBasicType(eBasicTypeVoid);
CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
std::array<CompilerType, 1> args{void_clang_type.GetPointerType()};

CompilerType method_type = m_clang_ast_context->CreateFunctionType(
void_clang_type, &void_ptr_clang_type, 1, false, 0);
void_clang_type, args, false, 0);

const bool is_virtual = false;
const bool is_static = false;
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::Update() {
lldb::ProcessSP process_sp = target_sp->GetProcessSP();
auto ptr_size = process_sp->GetAddressByteSize();
CompilerType void_type = ast_ctx->GetBasicType(lldb::eBasicTypeVoid);
std::array<CompilerType, 1> args{void_type};
CompilerType coro_func_type = ast_ctx->CreateFunctionType(
/*result_type=*/void_type, /*args=*/&void_type, /*num_args=*/1,
/*result_type=*/void_type, args,
/*is_variadic=*/false, /*qualifiers=*/0);
CompilerType coro_func_ptr_type = coro_func_type.GetPointerType();
m_resume_ptr_sp = CreateValueObjectFromAddress(
Expand Down
7 changes: 3 additions & 4 deletions lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ SymbolFileCTF::CreateFunction(const CTFFunction &ctf_function) {
llvm::inconvertibleErrorCode());

CompilerType func_type = m_ast->CreateFunctionType(
ret_type->GetFullCompilerType(), arg_types.data(), arg_types.size(),
ctf_function.variadic, 0, clang::CallingConv::CC_C);
ret_type->GetFullCompilerType(), arg_types, ctf_function.variadic, 0,
clang::CallingConv::CC_C);

Declaration decl;
return MakeType(ctf_function.uid, ConstString(ctf_function.name), 0, nullptr,
Expand Down Expand Up @@ -814,8 +814,7 @@ size_t SymbolFileCTF::ParseFunctions(CompileUnit &cu) {
// Create function type.
CompilerType func_type = m_ast->CreateFunctionType(
ret_type ? ret_type->GetFullCompilerType() : CompilerType(),
arg_types.data(), arg_types.size(), is_variadic, 0,
clang::CallingConv::CC_C);
arg_types, is_variadic, 0, clang::CallingConv::CC_C);
lldb::user_id_t function_type_uid = m_types.size() + 1;
TypeSP type_sp =
MakeType(function_type_uid, symbol->GetName(), 0, nullptr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1309,11 +1309,10 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,

// clang_type will get the function prototype clang type after this
// call
CompilerType clang_type =
m_ast.CreateFunctionType(return_clang_type, function_param_types.data(),
function_param_types.size(), is_variadic,
GetCXXMethodCVQuals(die, object_parameter),
calling_convention, attrs.ref_qual);
CompilerType clang_type = m_ast.CreateFunctionType(
return_clang_type, function_param_types, is_variadic,
GetCXXMethodCVQuals(die, object_parameter), calling_convention,
attrs.ref_qual);

if (attrs.name) {
bool type_handled = false;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,8 @@ clang::QualType PdbAstBuilder::CreateFunctionType(
return {};

CompilerType return_ct = ToCompilerType(return_type);
CompilerType func_sig_ast_type = m_clang.CreateFunctionType(
return_ct, arg_types.data(), arg_types.size(), is_variadic, 0, *cc);
CompilerType func_sig_ast_type =
m_clang.CreateFunctionType(return_ct, arg_types, is_variadic, 0, *cc);

return clang::QualType::getFromOpaquePtr(
func_sig_ast_type.GetOpaqueQualType());
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
if (func_sig->isVolatileType())
type_quals |= clang::Qualifiers::Volatile;
auto cc = TranslateCallingConvention(func_sig->getCallingConvention());
CompilerType func_sig_ast_type =
m_ast.CreateFunctionType(return_ast_type, arg_list.data(),
arg_list.size(), is_variadic, type_quals, cc);
CompilerType func_sig_ast_type = m_ast.CreateFunctionType(
return_ast_type, arg_list, is_variadic, type_quals, cc);

AddSourceInfoToDecl(type, decl);
return m_ast.GetSymbolFile()->MakeType(
Expand Down
17 changes: 7 additions & 10 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2181,25 +2181,22 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
}

CompilerType TypeSystemClang::CreateFunctionType(
const CompilerType &result_type, const CompilerType *args,
unsigned num_args, bool is_variadic, unsigned type_quals,
clang::CallingConv cc, clang::RefQualifierKind ref_qual) {
const CompilerType &result_type, llvm::ArrayRef<CompilerType> args,
bool is_variadic, unsigned type_quals, clang::CallingConv cc,
clang::RefQualifierKind ref_qual) {
if (!result_type || !ClangUtil::IsClangType(result_type))
return CompilerType(); // invalid return type

std::vector<QualType> qual_type_args;
if (num_args > 0 && args == nullptr)
return CompilerType(); // invalid argument array passed in

// Verify that all arguments are valid and the right type
for (unsigned i = 0; i < num_args; ++i) {
if (args[i]) {
for (const auto &arg : args) {
if (arg) {
// Make sure we have a clang type in args[i] and not a type from another
// language whose name might match
const bool is_clang_type = ClangUtil::IsClangType(args[i]);
const bool is_clang_type = ClangUtil::IsClangType(arg);
lldbassert(is_clang_type);
if (is_clang_type)
qual_type_args.push_back(ClangUtil::GetQualType(args[i]));
qual_type_args.push_back(ClangUtil::GetQualType(arg));
else
return CompilerType(); // invalid argument type (must be a clang type)
} else
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ class TypeSystemClang : public TypeSystem {
clang::StorageClass storage, bool is_inline);

CompilerType
CreateFunctionType(const CompilerType &result_type, const CompilerType *args,
unsigned num_args, bool is_variadic, unsigned type_quals,
clang::CallingConv cc = clang::CC_C,
CreateFunctionType(const CompilerType &result_type,
llvm::ArrayRef<CompilerType> args, bool is_variadic,
unsigned type_quals, clang::CallingConv cc = clang::CC_C,
clang::RefQualifierKind ref_qual = clang::RQ_None);

clang::ParmVarDecl *
Expand Down
38 changes: 17 additions & 21 deletions lldb/unittests/Symbol/TestTypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,7 @@ TEST_F(TestTypeSystemClang, TestFunctionTemplateConstruction) {
clang::TranslationUnitDecl *TU = m_ast->GetTranslationUnitDecl();

// Prepare the declarations/types we need for the template.
CompilerType clang_type =
m_ast->CreateFunctionType(int_type, nullptr, 0U, false, 0U);
CompilerType clang_type = m_ast->CreateFunctionType(int_type, {}, false, 0U);
FunctionDecl *func = m_ast->CreateFunctionDeclaration(
TU, OptionalClangModuleID(), "foo", clang_type, StorageClass::SC_None,
false);
Expand Down Expand Up @@ -895,8 +894,7 @@ TEST_F(TestTypeSystemClang, TestFunctionTemplateInRecordConstruction) {
clang::TagDecl *record = ClangUtil::GetAsTagDecl(record_type);

// Prepare the declarations/types we need for the template.
CompilerType clang_type =
m_ast->CreateFunctionType(int_type, nullptr, 0U, false, 0U);
CompilerType clang_type = m_ast->CreateFunctionType(int_type, {}, false, 0U);
// We create the FunctionDecl for the template in the TU DeclContext because:
// 1. FunctionDecls can't be in a Record (only CXXMethodDecls can).
// 2. It is mirroring the behavior of DWARFASTParserClang::ParseSubroutine.
Expand Down Expand Up @@ -930,10 +928,9 @@ TEST_F(TestTypeSystemClang, TestDeletingImplicitCopyCstrDueToMoveCStr) {

// Create a move constructor that will delete the implicit copy constructor.
CompilerType return_type = m_ast->GetBasicType(lldb::eBasicTypeVoid);
CompilerType param_type = t.GetRValueReferenceType();
CompilerType function_type =
m_ast->CreateFunctionType(return_type, &param_type, /*num_params*/ 1,
/*variadic=*/false, /*quals*/ 0U);
std::array<CompilerType, 1> args{t.GetRValueReferenceType()};
CompilerType function_type = m_ast->CreateFunctionType(
return_type, args, /*variadic=*/false, /*quals*/ 0U);
bool is_virtual = false;
bool is_static = false;
bool is_inline = false;
Expand Down Expand Up @@ -974,20 +971,20 @@ TEST_F(TestTypeSystemClang, TestNotDeletingUserCopyCstrDueToMoveCStr) {
bool is_artificial = false;
// Create a move constructor.
{
CompilerType param_type = t.GetRValueReferenceType();
CompilerType function_type =
m_ast->CreateFunctionType(return_type, &param_type, /*num_params*/ 1,
/*variadic=*/false, /*quals*/ 0U);
std::array<CompilerType, 1> args{t.GetRValueReferenceType()};
CompilerType function_type = m_ast->CreateFunctionType(
return_type, args, /*variadic=*/false, /*quals*/ 0U);
m_ast->AddMethodToCXXRecordType(
t.GetOpaqueQualType(), class_name, nullptr, function_type,
lldb::AccessType::eAccessPublic, is_virtual, is_static, is_inline,
is_explicit, is_attr_used, is_artificial);
}
// Create a copy constructor.
{
CompilerType param_type = t.GetLValueReferenceType().AddConstModifier();
std::array<CompilerType, 1> args{
t.GetLValueReferenceType().AddConstModifier()};
CompilerType function_type =
m_ast->CreateFunctionType(return_type, &param_type, /*num_params*/ 1,
m_ast->CreateFunctionType(return_type, args,
/*variadic=*/false, /*quals*/ 0U);
m_ast->AddMethodToCXXRecordType(
t.GetOpaqueQualType(), class_name, nullptr, function_type,
Expand All @@ -1012,10 +1009,9 @@ TEST_F(TestTypeSystemClang, AddMethodToObjCObjectType) {

// Add a method to the interface.
std::vector<CompilerType> args;
CompilerType func_type =
m_ast->CreateFunctionType(m_ast->GetBasicType(lldb::eBasicTypeInt),
args.data(), args.size(), /*variadic*/ false,
/*quals*/ 0, clang::CallingConv::CC_C);
CompilerType func_type = m_ast->CreateFunctionType(
m_ast->GetBasicType(lldb::eBasicTypeInt), args, /*variadic*/ false,
/*quals*/ 0, clang::CallingConv::CC_C);
bool variadic = false;
bool artificial = false;
bool objc_direct = false;
Expand Down Expand Up @@ -1098,9 +1094,9 @@ TEST_F(TestTypeSystemClang, AddMethodToCXXRecordType_ParmVarDecls) {
llvm::SmallVector<CompilerType> param_types{
m_ast->GetBasicType(lldb::eBasicTypeInt),
m_ast->GetBasicType(lldb::eBasicTypeShort)};
CompilerType function_type = m_ast->CreateFunctionType(
return_type, param_types.data(), /*num_params*/ param_types.size(),
/*variadic=*/false, /*quals*/ 0U);
CompilerType function_type =
m_ast->CreateFunctionType(return_type, param_types,
/*variadic=*/false, /*quals*/ 0U);
m_ast->AddMethodToCXXRecordType(
t.GetOpaqueQualType(), "myFunc", nullptr, function_type,
lldb::AccessType::eAccessPublic, is_virtual, is_static, is_inline,
Expand Down
Loading