Skip to content

Commit 8d77b94

Browse files
committed
Get the alignment correct for subclasses of AvailabilitySpec.
Apart from being required by the standard, we also store these objects in a PointerIntPair, so it's important to not misalign them. (We should have an -fsanitize=undefined bot to catch this.)
1 parent 8917eb0 commit 8d77b94

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

include/swift/AST/AvailabilitySpec.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ class VersionConstraintAvailabilitySpec : public AvailabilitySpec {
8989
static bool classof(const AvailabilitySpec *Spec) {
9090
return Spec->getKind() == AvailabilitySpecKind::VersionConstraint;
9191
}
92+
93+
void *
94+
operator new(size_t Bytes, ASTContext &C,
95+
unsigned Alignment = alignof(VersionConstraintAvailabilitySpec)){
96+
return AvailabilitySpec::operator new(Bytes, C, Alignment);
97+
}
9298
};
9399

94100
/// A wildcard availability specification that guards execution
@@ -115,6 +121,12 @@ class OtherPlatformAvailabilitySpec : public AvailabilitySpec {
115121
static bool classof(const AvailabilitySpec *Spec) {
116122
return Spec->getKind() == AvailabilitySpecKind::OtherPlatform;
117123
}
124+
125+
void *
126+
operator new(size_t Bytes, ASTContext &C,
127+
unsigned Alignment = alignof(OtherPlatformAvailabilitySpec)) {
128+
return AvailabilitySpec::operator new(Bytes, C, Alignment);
129+
}
118130
};
119131

120132
} // end namespace swift

0 commit comments

Comments
 (0)