Skip to content

Commit 261a9df

Browse files
authored
Merge pull request swiftlang#40970 from xedin/add-padding-to-generic-env-desc
[IRGen] Pad generic environment descriptor before adding requirements
2 parents 359ee9b + cee7d1c commit 261a9df

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
@@ -3730,6 +3730,11 @@ llvm::Constant *IRGenModule::getAddrOfGenericEnvironment(
37303730
.getIntValue());
37313731
});
37323732

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

0 commit comments

Comments
 (0)