C ABI: Do not pass empty structs as parameters at all

This is most visible on x86 (32-bit), where the stack
alignment is off otherwise.

This change is quite messy because many places assumed
that there was always exactly one LLVM parameter per
TypeFunction::parameters entry.
This commit is contained in:
David Nadlinger 2015-08-22 22:12:23 +02:00
parent 410203b37a
commit ee50259dfd
5 changed files with 130 additions and 91 deletions

View file

@ -158,7 +158,7 @@ DValue* DtoNestedVariable(Loc& loc, Type* astype, VarDeclaration* vd, bool byref
Logger::cout() << "Addr: " << *val << '\n';
Logger::cout() << "of type: " << *val->getType() << '\n';
}
if (byref || (vd->isParameter() && getIrParameter(vd)->arg->byref)) {
if (byref || (vd->isParameter() && getIrParameter(vd)->arg && getIrParameter(vd)->arg->byref)) {
val = DtoAlignedLoad(val);
//dwarfOpDeref(dwarfAddr);
IF_LOG {
@ -364,9 +364,11 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
irLocal->nestedIndex = types.size();
irLocal->nestedDepth = depth;
if (vd->isParameter()) {
// Parameters will have storage associated with them (to handle byref etc.),
// so handle those cases specially by storing a pointer instead of a value.
if (vd->isParameter() && getIrParameter(vd)->arg) {
// Parameters that are part of the LLVM signature will have
// storage associated with them (to handle byref etc.), so
// handle those cases specially by storing a pointer instead
// of a value.
const IrParameter* irparam = getIrParameter(vd);
const bool refout = vd->storage_class & (STCref | STCout);
const bool lazy = vd->storage_class & STClazy;
@ -479,7 +481,7 @@ void DtoCreateNestedContext(FuncDeclaration* fd) {
LOG_SCOPE
IrParameter* parm = getIrParameter(vd);
if (parm->arg->byref)
if (parm->arg && parm->arg->byref)
{
storeVariable(vd, gep);
}