Skip to content

Commit

Permalink
Use Attribute::get* methods for ByVal and SRet
Browse files Browse the repository at this point in the history
Fixes "Attribute 'byval' type does not match parameter!" errors
  • Loading branch information
Jcd1230 committed Jul 18, 2021
1 parent 85034d5 commit 0de11ce
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/tcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,13 @@ struct CCallingConv {
}

template <typename FnOrCall>
void addSRetAttr(FnOrCall *r, int idx) {
r->addAttribute(idx, Attribute::StructRet);
void addSRetAttr(FnOrCall *r, int idx, Type* ty) {
r->addAttribute(idx, Attribute::getWithStructRetType(*CU->TT->ctx, ty));
r->addAttribute(idx, Attribute::NoAlias);
}
template <typename FnOrCall>
void addByValAttr(FnOrCall *r, int idx) {
r->addAttribute(idx, Attribute::ByVal);
void addByValAttr(FnOrCall *r, int idx, Type* ty) {
r->addAttribute(idx, llvm::Attribute::getWithByValType(*CU->TT->ctx, ty));
}
template <typename FnOrCall>
void addExtAttrIfNeeded(TType *t, FnOrCall *r, int idx) {
Expand All @@ -976,14 +976,14 @@ struct CCallingConv {
addExtAttrIfNeeded(info->returntype.type, r, 0);
int argidx = 1;
if (info->returntype.kind == C_AGGREGATE_MEM) {
addSRetAttr(r, argidx);
addSRetAttr(r, argidx, info->returntype.cctype);
argidx++;
}
for (size_t i = 0; i < info->paramtypes.size(); i++) {
Argument *v = &info->paramtypes[i];
if (v->kind == C_AGGREGATE_MEM) {
#ifndef _WIN32
addByValAttr(r, argidx);
addByValAttr(r, argidx, v->cctype);
#endif
}
addExtAttrIfNeeded(v->type, r, argidx);
Expand Down

0 comments on commit 0de11ce

Please sign in to comment.