IRGen: Only mark field offset globals as constant if they won't be updated at runtime

Even if we have a constant value, we might be emitting a legacy layout
that can be updated in place by newer runtimes. In this case, clients
cannot assume the field offsets are constant, and the globals cannot
be constant either.

Part of <rdar://problem/17528739>.
This commit is contained in:
Slava Pestov
2018-10-31 20:44:07 -04:00
parent b5aa1b3b16
commit dbd116119e
4 changed files with 35 additions and 21 deletions

View File

@@ -993,17 +993,17 @@ void IRGenModule::emitClassDecl(ClassDecl *D) {
SILType selfType = getSelfType(D);
auto &classTI = getTypeInfo(selfType).as<ClassTypeInfo>();
// FIXME: For now, always use the fragile layout when emitting metadata.
// Use the fragile layout when emitting metadata.
auto &fragileLayout =
classTI.getClassLayout(*this, selfType, /*forBackwardDeployment=*/true);
// ... but still compute the resilient layout for better test coverage.
// The resilient layout tells us what parts of the metadata can be
// updated at runtime by the Objective-C metadata update callback.
auto &resilientLayout =
classTI.getClassLayout(*this, selfType, /*forBackwardDeployment=*/false);
(void) resilientLayout;
// Emit the class metadata.
emitClassMetadata(*this, D, fragileLayout);
emitClassMetadata(*this, D, fragileLayout, resilientLayout);
IRGen.addClassForEagerInitialization(D);