Skip to content

Merge pull request #9393 from shajrawi/arg_param_mismatch #9399

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 1 commit into from
May 8, 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
20 changes: 20 additions & 0 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ static SILType getNewOptionalFunctionType(GenericEnvironment *GenericEnv,
auto newType = OptionalType::get(optKind, currCanType);
CanType newCanType = newType->getCanonicalType();
newSILType = SILType::getPrimitiveObjectType(newCanType);
if (storageType.isAddress()) {
newSILType = newSILType.getAddressType();
}
}
}
}
Expand Down Expand Up @@ -276,6 +279,9 @@ getNewArgTys(GenericEnvironment *GenericEnv, ArrayRef<SILParameterInfo> params,
currSILFunctionType->getParameters(), Mod)) {
SILType newSILType =
getNewSILFunctionType(GenericEnv, currSILFunctionType, Mod);
if (storageType.isAddress()) {
newSILType = newSILType.getAddressType();
}
auto newParam = SILParameterInfo(newSILType.getSwiftRValueType(),
param.getConvention());
newArgTys.push_back(newParam);
Expand Down Expand Up @@ -311,6 +317,9 @@ static SILType getNewSILType(GenericEnvironment *GenericEnv,
if (containsLargeLoadable(GenericEnv, currSILFunctionType->getParameters(),
Mod)) {
newSILType = getNewSILFunctionType(GenericEnv, currSILFunctionType, Mod);
if (storageType.isAddress()) {
newSILType = newSILType.getAddressType();
}
}
} else if (isLargeLoadableType(GenericEnv, storageType, Mod)) {
newSILType = storageType.getAddressType();
Expand Down Expand Up @@ -427,6 +436,7 @@ void LargeValueVisitor::mapValueStorage() {
case ValueKind::StructElementAddrInst:
case ValueKind::RefTailAddrInst:
case ValueKind::RefElementAddrInst:
case ValueKind::BeginAccessInst:
case ValueKind::EnumInst: {
// TODO Any more instructions to add here?
visitResultTyInst(currIns);
Expand Down Expand Up @@ -1315,6 +1325,9 @@ static void castTupleInstr(SILInstruction *instr, IRGenModule &Mod) {
genEnv = getGenericEnvironment(instr->getModule(), canFuncType);
}
SILType newSILType = getNewSILFunctionType(genEnv, funcType, Mod);
if (currSILType.isAddress()) {
newSILType = newSILType.getAddressType();
}
auto II = instr->getIterator();
++II;
SILBuilder castBuilder(II);
Expand Down Expand Up @@ -1594,6 +1607,13 @@ static void rewriteFunction(StructLoweringState &pass,
newSILType.getAddressType());
break;
}
case ValueKind::BeginAccessInst: {
auto *convInstr = dyn_cast<BeginAccessInst>(instr);
newInstr = resultTyBuilder.createBeginAccess(Loc, convInstr->getOperand(),
convInstr->getAccessKind(),
convInstr->getEnforcement());
break;
}
case ValueKind::EnumInst: {
EnumInst *convInstr = dyn_cast<EnumInst>(instr);
SILValue operand =
Expand Down
28 changes: 27 additions & 1 deletion test/IRGen/big_types_corner_cases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ public struct BigStruct {
var i8 : Int32 = 8
}

func takeClosure(execute block: () -> Void) {
}

class OptionalInoutFuncType {
private var lp : BigStruct?
private var _handler : ((BigStruct?, Error?) -> ())?

func execute(_ error: Error?) {
var p : BigStruct?
var handler: ((BigStruct?, Error?) -> ())?

takeClosure {
p = self.lp
handler = self._handler
self._handler = nil
}

handler?(p, error)
}
}

// CHECK-LABEL: define{{( protected)?}} internal swiftcc void @_T022big_types_corner_cases21OptionalInoutFuncTypeC7executeys5Error_pSgFyycfU_(%T22big_types_corner_cases9BigStructVSg* nocapture dereferenceable({{.*}}), %T22big_types_corner_cases21OptionalInoutFuncTypeC*, %T22big_types_corner_cases9BigStructVSgs5Error_pSgIxcx_Sg* nocapture dereferenceable({{.*}})
// CHECK: call void @_T0SqWy
// CHECK: call void @_T0SqWe
// CHECK: ret void

public func f1_returns_BigType(_ x: BigStruct) -> BigStruct {
return x
}
Expand Down Expand Up @@ -84,4 +110,4 @@ class Foo {
// CHECK: getelementptr inbounds %T22big_types_corner_cases3FooC, %T22big_types_corner_cases3FooC*
// CHECK: getelementptr inbounds void (i8*, %swift.refcounted*, %T22big_types_corner_cases3FooC*)*, void (i8*, %swift.refcounted*, %T22big_types_corner_cases3FooC*)**
// CHECK: call noalias %swift.refcounted* @swift_rt_swift_allocObject(%swift.type* getelementptr inbounds (%swift.full_boxmetadata, %swift.full_boxmetadata*
// CHECK: ret { i8*, %swift.refcounted* }
// CHECK: ret { i8*, %swift.refcounted* }