comparison gen/llvmhelpers.cpp @ 1029:4d366a75d95f

Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 03 Mar 2009 15:08:26 +0100
parents 80490f65d4e1
children 39f12f5aa515
comparison
equal deleted inserted replaced
1028:964af20461a9 1029:4d366a75d95f
1563 if (M) 1563 if (M)
1564 return M == gIR->dmodule; 1564 return M == gIR->dmodule;
1565 return false; 1565 return false;
1566 #endif 1566 #endif
1567 } 1567 }
1568
1569 //////////////////////////////////////////////////////////////////////////////////////////
1570
1571 bool hasUnalignedFields(Type* t)
1572 {
1573 t = t->toBasetype();
1574 if (t->ty != Tstruct)
1575 return false;
1576
1577 TypeStruct* ts = (TypeStruct*)t;
1578 if (ts->unaligned)
1579 return (ts->unaligned == 2);
1580
1581 StructDeclaration* sym = ts->sym;
1582
1583 // go through all the fields and try to find something unaligned
1584 ts->unaligned = 2;
1585 for (int i = 0; i < sym->fields.dim; i++)
1586 {
1587 VarDeclaration* f = (VarDeclaration*)sym->fields.data[i];
1588 unsigned a = f->type->alignsize() - 1;
1589 if (((f->offset + a) & ~a) != f->offset)
1590 return true;
1591 else if (f->type->toBasetype()->ty == Tstruct && hasUnalignedFields(f->type))
1592 return true;
1593 }
1594
1595 ts->unaligned = 1;
1596 return false;
1597 }