Skip to content

Commit

Permalink
Fix AArch64 variadics?
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Aug 7, 2018
1 parent b43de06 commit e0b8b9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions gen/abi-aarch64.cpp
Expand Up @@ -107,7 +107,7 @@ struct AArch64TargetABI : TargetABI {
}

LLValue *prepareVaStart(DLValue *ap) override {
// Since the user only created a char* pointer (ap) on the stack before
// Since the user only created a __va_list* pointer (ap) on the stack before
// invoking va_start, we first need to allocate the actual __va_list struct
// and set `ap` to its address.
LLValue *valistmem = DtoRawAlloca(getValistType(), 0, "__va_list_mem");
Expand All @@ -124,22 +124,23 @@ struct AArch64TargetABI : TargetABI {
DtoStore(valistmem,
DtoBitCast(DtoLVal(dest), getPtrToType(valistmem->getType())));
// Then fill the new struct with a bitcopy of the source struct.
// `src` is a char* pointer to the source struct.
// `src` is a __va_list* pointer to the source struct.
DtoMemCpy(valistmem, DtoRVal(src));
}

LLValue *prepareVaArg(DLValue *ap) override {
// Pass a i8* pointer to the actual __va_list struct to LLVM's va_arg
// intrinsic.
return DtoRVal(ap);
return DtoBitCast(DtoRVal(ap), getVoidPtrType());
}

Type *vaListType() override {
// We need to pass the actual va_list type for correct mangling. Simply
// using TypeIdentifier here is a bit wonky but works, as long as the name
// is actually available in the scope (this is what DMD does, so if a better
// solution is found there, this should be adapted).
return createTypeIdentifier(Loc(), Identifier::idPool("__va_list"));
return createTypeIdentifier(Loc(), Identifier::idPool("__va_list"))
->pointerTo();
}

const char *objcMsgSendFunc(Type *ret, IrFuncTy &fty) override {
Expand Down
6 changes: 3 additions & 3 deletions gen/abi-x86-64.cpp
Expand Up @@ -397,7 +397,7 @@ LLType *X86_64TargetABI::getValistType() {
}

LLValue *X86_64TargetABI::prepareVaStart(DLValue *ap) {
// Since the user only created a char* pointer (ap) on the stack before
// Since the user only created a __va_list* pointer (ap) on the stack before
// invoking va_start, we first need to allocate the actual __va_list struct
// and set `ap` to its address.
LLValue *valistmem = DtoRawAlloca(getValistType(), 0, "__va_list_mem");
Expand All @@ -414,14 +414,14 @@ void X86_64TargetABI::vaCopy(DLValue *dest, DValue *src) {
DtoStore(valistmem,
DtoBitCast(DtoLVal(dest), getPtrToType(valistmem->getType())));
// Then fill the new struct with a bitcopy of the source struct.
// `src` is a char* pointer to the source struct.
// `src` is a __va_list* pointer to the source struct.
DtoMemCpy(valistmem, DtoRVal(src));
}

LLValue *X86_64TargetABI::prepareVaArg(DLValue *ap) {
// Pass a i8* pointer to the actual __va_list struct to LLVM's va_arg
// intrinsic.
return DtoRVal(ap);
return DtoBitCast(DtoRVal(ap), getVoidPtrType());
}

Type *X86_64TargetABI::vaListType() {
Expand Down

0 comments on commit e0b8b9b

Please sign in to comment.