| 613 | } |
| 614 | |
| 615 | int BfFieldInstance::GetAlign(int packing) |
| 616 | { |
| 617 | int align = mResolvedType->mAlign; |
| 618 | if (IsAppendedObject()) |
| 619 | align = mResolvedType->ToTypeInstance()->mInstAlign; |
| 620 | if (packing > 0) |
| 621 | align = BF_MIN(align, packing); |
| 622 | if (mCustomAttributes != NULL) |
| 623 | { |
| 624 | auto module = mOwner->mModule; |
| 625 | for (auto& attrib : mCustomAttributes->mAttributes) |
| 626 | { |
| 627 | if (attrib.mType->IsInstanceOf(module->mCompiler->mAlignAttributeTypeDef)) |
| 628 | { |
| 629 | align = 16; // System conservative default |
| 630 | |
| 631 | if (!attrib.mCtorArgs.IsEmpty()) |
| 632 | { |
| 633 | BfIRConstHolder* constHolder = module->mCurTypeInstance->mConstHolder; |
| 634 | auto constant = constHolder->GetConstant(attrib.mCtorArgs[0]); |
| 635 | if (constant != NULL) |
| 636 | { |
| 637 | int alignOverride = (int)BF_MAX(1, constant->mInt64); |
| 638 | if ((alignOverride & (alignOverride - 1)) == 0) |
| 639 | align = alignOverride; |
| 640 | else |
| 641 | module->Fail("Alignment must be a power of 2", attrib.GetRefNode()); |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | return align; |
| 648 | } |
| 649 | |
| 650 | bool BfFieldInstance::IsAppendedObject() |
| 651 | { |
no test coverage detected