Skip to content

Large types bug fixes - cherry-pick from master #9179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ static bool modifiableFunction(CanSILFunctionType funcType) {
// C functions should use the old ABI
return false;
}
if (funcType->getRepresentation() == SILFunctionTypeRepresentation::Method) {
// C functions should use the old ABI
return false;
}
return true;
}

Expand Down Expand Up @@ -396,10 +392,6 @@ static bool modifiableApply(ApplySite applySite, irgen::IRGenModule &Mod) {
SILFunctionTypeRepresentation::CFunctionPointer) {
return false;
}
if (applySite.getSubstCalleeType()->getRepresentation() ==
SILFunctionTypeRepresentation::Method) {
return false;
}
auto callee = applySite.getCallee();
if (dyn_cast<ProjectBlockStorageInst>(callee)) {
return false;
Expand All @@ -425,17 +417,18 @@ void LargeValueVisitor::visitApply(ApplySite applySite) {
SILValue currOperand = operand.get();
SILType silType = currOperand->getType();
SILType newSilType = getNewSILType(genEnv, silType, pass.Mod);
if (silType != newSilType) {
if (silType != newSilType ||
std::find(pass.largeLoadableArgs.begin(), pass.largeLoadableArgs.end(),
currOperand) != pass.largeLoadableArgs.end() ||
std::find(pass.funcSigArgs.begin(), pass.funcSigArgs.end(),
currOperand) != pass.funcSigArgs.end()) {
pass.applies.push_back(applySite.getInstruction());
return;
}
}
}

static bool isMethodInstUnmodifiable(MethodInst *instr) {
if (dyn_cast<ClassMethodInst>(instr)) {
return true;
}
for (auto *user : instr->getUses()) {
if (ApplySite::isa(user->getUser())) {
ApplySite applySite = ApplySite(user->getUser());
Expand All @@ -447,10 +440,6 @@ static bool isMethodInstUnmodifiable(MethodInst *instr) {
SILFunctionTypeRepresentation::CFunctionPointer) {
return true;
}
if (applySite.getSubstCalleeType()->getRepresentation() ==
SILFunctionTypeRepresentation::Method) {
return true;
}
}
}
return false;
Expand Down
29 changes: 18 additions & 11 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2244,9 +2244,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {

void checkClassMethodInst(ClassMethodInst *CMI) {
auto overrideTy = TC.getConstantOverrideType(CMI->getMember());
requireSameType(CMI->getType(),
SILType::getPrimitiveObjectType(overrideTy),
"result type of class_method must match abstracted type of method");
if (CMI->getModule().getStage() != SILStage::Lowered) {
requireSameType(
CMI->getType(), SILType::getPrimitiveObjectType(overrideTy),
"result type of class_method must match abstracted type of method");
}
auto methodType = requireObjectType(SILFunctionType, CMI,
"result of class_method");
require(!methodType->getExtInfo().hasContext(),
Expand Down Expand Up @@ -2280,8 +2282,11 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {

void checkSuperMethodInst(SuperMethodInst *CMI) {
auto overrideTy = TC.getConstantOverrideType(CMI->getMember());
requireSameType(CMI->getType(), SILType::getPrimitiveObjectType(overrideTy),
"result type of super_method must match abstracted type of method");
if (CMI->getModule().getStage() != SILStage::Lowered) {
requireSameType(
CMI->getType(), SILType::getPrimitiveObjectType(overrideTy),
"result type of super_method must match abstracted type of method");
}
auto methodType = requireObjectType(SILFunctionType, CMI,
"result of super_method");
require(!methodType->getExtInfo().hasContext(),
Expand Down Expand Up @@ -4226,12 +4231,14 @@ void SILVTable::verify(const SILModule &M) const {
llvm::raw_svector_ostream os(baseName);
entry.Method.print(os);
}

SILVerifier(*entry.Implementation)
.requireABICompatibleFunctionTypes(
baseInfo.getSILType().castTo<SILFunctionType>(),
entry.Implementation->getLoweredFunctionType(),
"vtable entry for " + baseName + " must be ABI-compatible");

if (M.getStage() != SILStage::Lowered) {
SILVerifier(*entry.Implementation)
.requireABICompatibleFunctionTypes(
baseInfo.getSILType().castTo<SILFunctionType>(),
entry.Implementation->getLoweredFunctionType(),
"vtable entry for " + baseName + " must be ABI-compatible");
}
}
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions test/IRGen/indirect_argument.sil
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ struct HugeAlignment {
// TODO: could be the context param
// CHECK-LABEL-64: define{{( protected)?}} swiftcc void @huge_method(%T17indirect_argument4HugeV* noalias nocapture dereferenceable({{.*}}))
// CHECK-LABEL-32: define{{( protected)?}} swiftcc void @huge_method(%T17indirect_argument4HugeV* noalias nocapture swiftself dereferenceable({{.*}}))
// CHECK-64: call swiftcc void @huge_method(%T17indirect_argument4HugeV* noalias nocapture dereferenceable({{.*}})
// CHECK-32: call swiftcc void @huge_method(%T17indirect_argument4HugeV* noalias nocapture swiftself dereferenceable({{.*}})
// CHECK: call swiftcc void @huge_method(%T17indirect_argument4HugeV* noalias nocapture swiftself dereferenceable({{.*}})
sil @huge_method : $@convention(method) Huge -> () {
entry(%x : $Huge):
%f = function_ref @huge_method : $@convention(method) Huge -> ()
Expand Down Expand Up @@ -61,7 +60,8 @@ entry(%o : $*Huge, %x : $Huge):
}

// CHECK-LABEL: define{{( protected)?}} swiftcc void @huge_partial_application(%T17indirect_argument4HugeV* noalias nocapture dereferenceable({{.*}}), %T17indirect_argument4HugeV* noalias nocapture dereferenceable({{.*}}))
// CHECK: [[CLOSURE:%.*]] = call noalias %swift.refcounted* @swift_rt_swift_allocObject
// CHECK-32: [[CLOSURE:%.*]] = call noalias %swift.refcounted* @swift_rt_swift_allocObject
// CHECK-64: [[CLOSURE:%.*]] = call noalias %swift.refcounted* @swift_rt_swift_allocObject
// CHECK: bitcast %swift.refcounted* [[CLOSURE]] to <{ %swift.refcounted, %T17indirect_argument4HugeV }>*
// CHECK: call void @llvm.memcpy
// CHECK-64: call swiftcc void @_T024huge_partial_applicationTA(%T17indirect_argument4HugeV* noalias nocapture dereferenceable(40) %0, %swift.refcounted* swiftself [[CLOSURE]])
Expand Down