Skip to content

Commit 2af1614

Browse files
committed
---
yaml --- r: 349376 b: refs/heads/master-next c: 4d1d2d7 h: refs/heads/master
1 parent 077951a commit 2af1614

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: d18e355344f07396acfbcde7279dd0be869b2341
3+
refs/heads/master-next: 4d1d2d7c41bf80e8239c6c345a89768f311aa961
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/lib/SILGen/SILGenStmt.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,18 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
961961
};
962962

963963
auto buildElementRValue = [&](SILLocation loc, SGFContext ctx) {
964-
return SGF.emitApplyMethod(
964+
RValue result;
965+
result = SGF.emitApplyMethod(
965966
loc, S->getIteratorNext(), buildArgumentSource(),
966-
PreparedArguments(ArrayRef<AnyFunctionType::Param>({})), ctx);
967+
PreparedArguments(ArrayRef<AnyFunctionType::Param>({})),
968+
S->getElementExpr() ? SGFContext() : ctx);
969+
if (S->getElementExpr()) {
970+
SILGenFunction::OpaqueValueRAII pushOpaqueValue(
971+
SGF, S->getElementExpr(),
972+
std::move(result).getAsSingleValue(SGF, loc));
973+
result = SGF.emitRValue(S->getConvertElementExpr(), ctx);
974+
}
975+
return result;
967976
};
968977
// Then emit the loop destination block.
969978
//
@@ -976,17 +985,7 @@ void StmtEmitter::visitForEachStmt(ForEachStmt *S) {
976985
{
977986
ArgumentScope innerForScope(SGF, SILLocation(S));
978987
SILLocation loc = SILLocation(S);
979-
RValue result;
980-
if (S->getElementExpr()) {
981-
result = buildElementRValue(loc, SGFContext());
982-
SILGenFunction::OpaqueValueRAII pushOpaqueValue(
983-
SGF, S->getElementExpr(),
984-
std::move(result).getAsSingleValue(SGF, loc));
985-
result = SGF.emitRValue(S->getConvertElementExpr(),
986-
SGFContext(nextInit.get()));
987-
} else {
988-
result = buildElementRValue(loc, SGFContext(nextInit.get()));
989-
}
988+
RValue result = buildElementRValue(loc, SGFContext(nextInit.get()));
990989
if (!result.isInContext()) {
991990
ArgumentSource(SILLocation(S->getSequence()),
992991
std::move(result).ensurePlusOne(SGF, loc))

branches/master-next/test/Profiler/pgo_foreach.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public func guessForEach1(x: Int32) -> Int32 {
4242
// IR-OPT-LABEL: define swiftcc i32 @$s9pgo_foreach10guessWhiles5Int32VAD1x_tF
4343

4444
public func guessForEach2(x: Int32) -> Int32 {
45-
// SIL: switch_enum {{.*}} : $Optional<(key: String, value: Int32)>, case #Optional.some!enumelt.1: {{.*}} !case_count(168), case #Optional.none!enumelt: {{.*}} !case_count(42)
45+
// SIL: switch_enum {{.*}} : $Optional<(String, Int32)>, case #Optional.some!enumelt.1: {{.*}} !case_count(168), case #Optional.none!enumelt: {{.*}} !case_count(42)
4646

4747
var ret : Int32 = 0
4848
let names = ["John" : Int32(1), "Paul" : Int32(2), "George" : Int32(3), "Ringo" : Int32(x)]

branches/master-next/test/SILGen/foreach.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,14 @@ func unusedArgPattern(_ xx: [Int]) {
592592
loopBodyEnd()
593593
}
594594
}
595+
596+
// Test for SR-11269. Make sure that the sil contains the needed upcast.
597+
//
598+
// CHECK-LABEL: sil hidden [ossa] @$s7foreach25genericFuncWithConversion4listySayxG_tAA1CCRbzlF
599+
// CHECK: bb2([[ITER_VAL:%.*]] : @owned $T):
600+
// CHECK: [[ITER_VAL_UPCAST:%.*]] = upcast [[ITER_VAL]] : $T to $C
601+
func genericFuncWithConversion<T: C>(list : [T]) {
602+
for item: C in list {
603+
print(item)
604+
}
605+
}

0 commit comments

Comments
 (0)