Skip to content

Commit cee7d1c

Browse files
committed
[IRGen] Pad generic environment descriptor before adding requirements
Since `TargetGenericEnvironmentDescriptor` uses trailing objects to store parameters, requirements and other information. IR Emission should pad the structure to be 4 bytes aligned before adding generic requirements, because that's the alignment expected by `TargetGenericRequirementDescriptor`.
1 parent 847b6c0 commit cee7d1c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/IRGen/ConstantBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ConstantAggregateBuilderBase
118118
}
119119

120120
void addAlignmentPadding(Alignment align) {
121-
auto misalignment = getNextOffsetFromGlobal() % IGM().getPointerAlignment();
121+
auto misalignment = getNextOffsetFromGlobal() % align;
122122
if (misalignment != Size(0))
123123
add(llvm::ConstantAggregateZero::get(
124124
llvm::ArrayType::get(IGM().Int8Ty,

lib/IRGen/GenProto.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,6 +3732,11 @@ llvm::Constant *IRGenModule::getAddrOfGenericEnvironment(
37323732
.getIntValue());
37333733
});
37343734

3735+
// Need to pad the structure after generic parameters
3736+
// up to four bytes because generic requirements that
3737+
// follow expect that alignment.
3738+
fields.addAlignmentPadding(Alignment(4));
3739+
37353740
// Generic requirements
37363741
irgen::addGenericRequirements(*this, fields, signature,
37373742
signature.getRequirements());

0 commit comments

Comments
 (0)