Skip to content

Commit

Permalink
Only include formal parameters in function for varargs call (#602)
Browse files Browse the repository at this point in the history
Fixes macOS M1 calling convention.
  • Loading branch information
elliottslaughter authored Aug 23, 2022
1 parent 0cf6be6 commit 184ed6a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/tcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -1175,7 +1176,8 @@ 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) {
Expand Down Expand Up @@ -1562,7 +1564,8 @@ struct CCallingConv {
arguments.push_back(type);
}
}
FunctionType *CreateFunctionType(Classification *info, bool isvararg) {
FunctionType *CreateFunctionType(Classification *info, int formal_params,
bool isvararg) {
std::vector<Type *> arguments;

Type *rt = NULL;
Expand Down Expand Up @@ -1597,8 +1600,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: {
Expand Down

0 comments on commit 184ed6a

Please sign in to comment.