From c2a30855eb4af188be8b2c140a0954dcbaf375f8 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Mon, 22 Aug 2022 14:37:17 -0700 Subject: [PATCH 1/2] Only include formal parameters in function for varargs call. --- src/tcompiler.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index 962a5aa6..fe0a99e7 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -1148,7 +1148,8 @@ struct CCallingConv { return Argument(C_AGGREGATE_REG, t, StructType::get(*CU->TT->ctx, elements)); } void Classify(Obj *ftype, Obj *params, Classification *info) { - Obj returntype; + Obj fparams, returntype; + ftype->obj("parameters", &fparams); ftype->obj("returntype", &returntype); int zero = 0; info->returntype = ClassifyArgument(&returntype, &zero, &zero, true); @@ -1175,7 +1176,7 @@ struct CCallingConv { params->objAt(i, &elem); info->paramtypes.push_back(ClassifyArgument(&elem, &nfloat, &nint, false)); } - info->fntype = CreateFunctionType(info, ftype->boolean("isvararg")); + info->fntype = CreateFunctionType(info, fparams.size(), ftype->boolean("isvararg")); } Classification *ClassifyFunction(Obj *fntyp) { @@ -1562,7 +1563,7 @@ struct CCallingConv { arguments.push_back(type); } } - FunctionType *CreateFunctionType(Classification *info, bool isvararg) { + FunctionType *CreateFunctionType(Classification *info, int formal_params, bool isvararg) { std::vector arguments; Type *rt = NULL; @@ -1597,8 +1598,12 @@ struct CCallingConv { assert(!"unhandled argument kind"); } break; } - - for (size_t i = 0; i < info->paramtypes.size(); i++) { + if (isvararg) { + assert(formal_params <= info->paramtypes.size()); + } else { + assert(formal_params == info->paramtypes.size()); + } + for (size_t i = 0; i < formal_params; i++) { Argument *a = &info->paramtypes[i]; switch (a->kind) { case C_PRIMITIVE: { From cf58149d674008e47595726435a3042aade454b9 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Mon, 22 Aug 2022 14:39:43 -0700 Subject: [PATCH 2/2] Format. --- src/tcompiler.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index fe0a99e7..ed58a474 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -1176,7 +1176,8 @@ struct CCallingConv { params->objAt(i, &elem); info->paramtypes.push_back(ClassifyArgument(&elem, &nfloat, &nint, false)); } - info->fntype = CreateFunctionType(info, fparams.size(), ftype->boolean("isvararg")); + info->fntype = + CreateFunctionType(info, fparams.size(), ftype->boolean("isvararg")); } Classification *ClassifyFunction(Obj *fntyp) { @@ -1563,7 +1564,8 @@ struct CCallingConv { arguments.push_back(type); } } - FunctionType *CreateFunctionType(Classification *info, int formal_params, bool isvararg) { + FunctionType *CreateFunctionType(Classification *info, int formal_params, + bool isvararg) { std::vector arguments; Type *rt = NULL;