Skip to content

Commit bd2788f

Browse files
committed
[lldb][TypeSystem][NFC] CreateFunctionType to take parameters by llvm::ArrayRef
1 parent 3ddc1e1 commit bd2788f

File tree

10 files changed

+40
-50
lines changed

10 files changed

+40
-50
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,10 +1978,10 @@ void ClangExpressionDeclMap::AddContextClassType(NameSearchContext &context,
19781978
copied_clang_type.GetCompleteType()) {
19791979
CompilerType void_clang_type =
19801980
m_clang_ast_context->GetBasicType(eBasicTypeVoid);
1981-
CompilerType void_ptr_clang_type = void_clang_type.GetPointerType();
1981+
std::array<CompilerType, 1> args{void_clang_type.GetPointerType()};
19821982

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

19861986
const bool is_virtual = false;
19871987
const bool is_static = false;

lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ ClangPersistentVariables::GetClangASTImporter() {
117117

118118
std::shared_ptr<ClangModulesDeclVendor>
119119
ClangPersistentVariables::GetClangModulesDeclVendor() {
120-
if (!m_modules_decl_vendor_sp) {
121-
m_modules_decl_vendor_sp.reset(
122-
ClangModulesDeclVendor::Create(*m_target_sp));
123-
}
120+
// if (!m_modules_decl_vendor_sp) {
121+
// m_modules_decl_vendor_sp.reset(
122+
// ClangModulesDeclVendor::Create(*m_target_sp));
123+
// }
124124
return m_modules_decl_vendor_sp;
125125
}
126126

lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::Update() {
150150
lldb::ProcessSP process_sp = target_sp->GetProcessSP();
151151
auto ptr_size = process_sp->GetAddressByteSize();
152152
CompilerType void_type = ast_ctx->GetBasicType(lldb::eBasicTypeVoid);
153+
std::array<CompilerType, 1> args{void_type};
153154
CompilerType coro_func_type = ast_ctx->CreateFunctionType(
154-
/*result_type=*/void_type, /*args=*/&void_type, /*num_args=*/1,
155+
/*result_type=*/void_type, args,
155156
/*is_variadic=*/false, /*qualifiers=*/0);
156157
CompilerType coro_func_ptr_type = coro_func_type.GetPointerType();
157158
m_resume_ptr_sp = CreateValueObjectFromAddress(

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ SymbolFileCTF::CreateFunction(const CTFFunction &ctf_function) {
489489
llvm::inconvertibleErrorCode());
490490

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

495495
Declaration decl;
496496
return MakeType(ctf_function.uid, ConstString(ctf_function.name), 0, nullptr,
@@ -814,8 +814,7 @@ size_t SymbolFileCTF::ParseFunctions(CompileUnit &cu) {
814814
// Create function type.
815815
CompilerType func_type = m_ast->CreateFunctionType(
816816
ret_type ? ret_type->GetFullCompilerType() : CompilerType(),
817-
arg_types.data(), arg_types.size(), is_variadic, 0,
818-
clang::CallingConv::CC_C);
817+
arg_types, is_variadic, 0, clang::CallingConv::CC_C);
819818
lldb::user_id_t function_type_uid = m_types.size() + 1;
820819
TypeSP type_sp =
821820
MakeType(function_type_uid, symbol->GetName(), 0, nullptr,

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,10 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
13091309

13101310
// clang_type will get the function prototype clang type after this
13111311
// call
1312-
CompilerType clang_type =
1313-
m_ast.CreateFunctionType(return_clang_type, function_param_types.data(),
1314-
function_param_types.size(), is_variadic,
1315-
GetCXXMethodCVQuals(die, object_parameter),
1316-
calling_convention, attrs.ref_qual);
1312+
CompilerType clang_type = m_ast.CreateFunctionType(
1313+
return_clang_type, function_param_types, is_variadic,
1314+
GetCXXMethodCVQuals(die, object_parameter), calling_convention,
1315+
attrs.ref_qual);
13171316

13181317
if (attrs.name) {
13191318
bool type_handled = false;

lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ clang::QualType PdbAstBuilder::CreateFunctionType(
12161216
return {};
12171217

12181218
CompilerType return_ct = ToCompilerType(return_type);
1219-
CompilerType func_sig_ast_type = m_clang.CreateFunctionType(
1220-
return_ct, arg_types.data(), arg_types.size(), is_variadic, 0, *cc);
1219+
CompilerType func_sig_ast_type =
1220+
m_clang.CreateFunctionType(return_ct, arg_types, is_variadic, 0, *cc);
12211221

12221222
return clang::QualType::getFromOpaquePtr(
12231223
func_sig_ast_type.GetOpaqueQualType());

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
653653
if (func_sig->isVolatileType())
654654
type_quals |= clang::Qualifiers::Volatile;
655655
auto cc = TranslateCallingConvention(func_sig->getCallingConvention());
656-
CompilerType func_sig_ast_type =
657-
m_ast.CreateFunctionType(return_ast_type, arg_list.data(),
658-
arg_list.size(), is_variadic, type_quals, cc);
656+
CompilerType func_sig_ast_type = m_ast.CreateFunctionType(
657+
return_ast_type, arg_list, is_variadic, type_quals, cc);
659658

660659
AddSourceInfoToDecl(type, decl);
661660
return m_ast.GetSymbolFile()->MakeType(

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,25 +2181,22 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
21812181
}
21822182

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

21902190
std::vector<QualType> qual_type_args;
2191-
if (num_args > 0 && args == nullptr)
2192-
return CompilerType(); // invalid argument array passed in
2193-
21942191
// Verify that all arguments are valid and the right type
2195-
for (unsigned i = 0; i < num_args; ++i) {
2196-
if (args[i]) {
2192+
for (const auto &arg : args) {
2193+
if (arg) {
21972194
// Make sure we have a clang type in args[i] and not a type from another
21982195
// language whose name might match
2199-
const bool is_clang_type = ClangUtil::IsClangType(args[i]);
2196+
const bool is_clang_type = ClangUtil::IsClangType(arg);
22002197
lldbassert(is_clang_type);
22012198
if (is_clang_type)
2202-
qual_type_args.push_back(ClangUtil::GetQualType(args[i]));
2199+
qual_type_args.push_back(ClangUtil::GetQualType(arg));
22032200
else
22042201
return CompilerType(); // invalid argument type (must be a clang type)
22052202
} else

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ class TypeSystemClang : public TypeSystem {
480480
clang::StorageClass storage, bool is_inline);
481481

482482
CompilerType
483-
CreateFunctionType(const CompilerType &result_type, const CompilerType *args,
484-
unsigned num_args, bool is_variadic, unsigned type_quals,
485-
clang::CallingConv cc = clang::CC_C,
483+
CreateFunctionType(const CompilerType &result_type,
484+
llvm::ArrayRef<CompilerType> args, bool is_variadic,
485+
unsigned type_quals, clang::CallingConv cc = clang::CC_C,
486486
clang::RefQualifierKind ref_qual = clang::RQ_None);
487487

488488
clang::ParmVarDecl *

lldb/unittests/Symbol/TestTypeSystemClang.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,7 @@ TEST_F(TestTypeSystemClang, TestFunctionTemplateConstruction) {
866866
clang::TranslationUnitDecl *TU = m_ast->GetTranslationUnitDecl();
867867

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

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

931929
// Create a move constructor that will delete the implicit copy constructor.
932930
CompilerType return_type = m_ast->GetBasicType(lldb::eBasicTypeVoid);
933-
CompilerType param_type = t.GetRValueReferenceType();
934-
CompilerType function_type =
935-
m_ast->CreateFunctionType(return_type, &param_type, /*num_params*/ 1,
936-
/*variadic=*/false, /*quals*/ 0U);
931+
std::array<CompilerType, 1> args{t.GetRValueReferenceType()};
932+
CompilerType function_type = m_ast->CreateFunctionType(
933+
return_type, args, /*variadic=*/false, /*quals*/ 0U);
937934
bool is_virtual = false;
938935
bool is_static = false;
939936
bool is_inline = false;
@@ -974,10 +971,9 @@ TEST_F(TestTypeSystemClang, TestNotDeletingUserCopyCstrDueToMoveCStr) {
974971
bool is_artificial = false;
975972
// Create a move constructor.
976973
{
977-
CompilerType param_type = t.GetRValueReferenceType();
978-
CompilerType function_type =
979-
m_ast->CreateFunctionType(return_type, &param_type, /*num_params*/ 1,
980-
/*variadic=*/false, /*quals*/ 0U);
974+
std::array<CompilerType, 1> args{t.GetRValueReferenceType()};
975+
CompilerType function_type = m_ast->CreateFunctionType(
976+
return_type, args, /*variadic=*/false, /*quals*/ 0U);
981977
m_ast->AddMethodToCXXRecordType(
982978
t.GetOpaqueQualType(), class_name, nullptr, function_type,
983979
lldb::AccessType::eAccessPublic, is_virtual, is_static, is_inline,
@@ -1012,10 +1008,9 @@ TEST_F(TestTypeSystemClang, AddMethodToObjCObjectType) {
10121008

10131009
// Add a method to the interface.
10141010
std::vector<CompilerType> args;
1015-
CompilerType func_type =
1016-
m_ast->CreateFunctionType(m_ast->GetBasicType(lldb::eBasicTypeInt),
1017-
args.data(), args.size(), /*variadic*/ false,
1018-
/*quals*/ 0, clang::CallingConv::CC_C);
1011+
CompilerType func_type = m_ast->CreateFunctionType(
1012+
m_ast->GetBasicType(lldb::eBasicTypeInt), args, /*variadic*/ false,
1013+
/*quals*/ 0, clang::CallingConv::CC_C);
10191014
bool variadic = false;
10201015
bool artificial = false;
10211016
bool objc_direct = false;

0 commit comments

Comments
 (0)