Skip to content

Commit c7e944f

Browse files
authored
Merge pull request swiftlang#31537 from eeckstein/fix-cowopt-5.3
[5.3] COWArrayOpts: fix a mis-compile related to owned function arguments
2 parents e8df655 + 9d365ef commit c7e944f

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,6 @@ static bool isRelease(SILInstruction *Inst, SILValue RetainedValue,
9999
return true;
100100
}
101101

102-
if (auto *AI = dyn_cast<ApplyInst>(Inst)) {
103-
if (auto *F = AI->getReferencedFunctionOrNull()) {
104-
auto Params = F->getLoweredFunctionType()->getParameters();
105-
auto Args = AI->getArguments();
106-
for (unsigned ArgIdx = 0, ArgEnd = Params.size(); ArgIdx != ArgEnd;
107-
++ArgIdx) {
108-
if (MatchedReleases.count(&AI->getArgumentRef(ArgIdx)))
109-
continue;
110-
if (!areArraysEqual(RCIA, Args[ArgIdx], RetainedValue, ArrayAddress))
111-
continue;
112-
ParameterConvention P = Params[ArgIdx].getConvention();
113-
if (P == ParameterConvention::Direct_Owned) {
114-
LLVM_DEBUG(llvm::dbgs() << " matching with release " << *Inst);
115-
MatchedReleases.insert(&AI->getArgumentRef(ArgIdx));
116-
return true;
117-
}
118-
}
119-
}
120-
}
121102
LLVM_DEBUG(llvm::dbgs() << " not a matching release " << *Inst);
122103
return false;
123104
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-run-simple-swift(-O) | %FileCheck %s
2+
3+
// REQUIRES: executable_test
4+
5+
6+
@inline(never)
7+
func testit(_ input: [[Int]]) -> [[Int]] {
8+
var result : [[Int]] = []
9+
for inputElementArray in input {
10+
var mutableElementArray = inputElementArray
11+
for _ in 0..<2 {
12+
// The COW-check for 'mutableElementArray' must not be hoisted out of this loop.
13+
for i in 0..<1 {
14+
mutableElementArray[i] += 1
15+
}
16+
result.append(mutableElementArray)
17+
}
18+
}
19+
return result
20+
}
21+
22+
// CHECK: {{\[\[1\], \[2\]\]}}
23+
print(testit([[0]]))

0 commit comments

Comments
 (0)