Skip to content

Commit 59a9ee8

Browse files
authored
Merge pull request #30347 from ravikandhadai/oslog-crash-in-inout-aliasable
2 parents 46bba7a + 36deac4 commit 59a9ee8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

lib/SILOptimizer/Mandatory/OSLogOptimization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,8 @@ SILInstruction *getInstructionFollowingValueDefinition(SILValue value) {
606606
/// \p value is a trivial type, return the value itself.
607607
SILValue makeOwnedCopyOfSILValue(SILValue value, SILFunction &fun) {
608608
SILType type = value->getType();
609-
if (type.isTrivial(fun))
609+
if (type.isTrivial(fun) || type.isAddress())
610610
return value;
611-
assert(!type.isAddress() && "cannot make owned copy of addresses");
612611

613612
SILInstruction *instAfterValueDefinition =
614613
getInstructionFollowingValueDefinition(value);

test/SILOptimizer/OSLogPrototypeCompileDiagnostics.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal enum Color {
7575

7676
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
7777

78-
// No error is expected here.
78+
// Invoking the log calls in unreachable code should not crash the compiler.
7979
func testUnreachableLogCall(h: Logger, c: Color) {
8080
let arg = 10
8181
switch c {
@@ -93,6 +93,14 @@ if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
9393
""")
9494
}
9595
}
96+
97+
// Passing InOut values to the logger should not crash the compiler.
98+
func foo(_ logger: Logger, _ mutableValue: inout String) {
99+
logger.log("FMFLabelledLocation: initialized with coder \(mutableValue)")
100+
// expected-error@-1 {{escaping closure captures 'inout' parameter 'mutableValue'}}
101+
// expected-note@-3 {{parameter 'mutableValue' is declared 'inout'}}
102+
// expected-note@-3 {{captured here}}
103+
}
96104
}
97105

98106
// This is an extension used only for testing a diagnostic that doesn't arise

test/SILOptimizer/OSLogPrototypeCompileTest.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,21 @@ if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
600600
}
601601
}
602602

603+
protocol Proto {
604+
var property: String { get set }
605+
}
606+
607+
// Test capturing of address-only types in autoclosures.
608+
609+
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
610+
// CHECK-LABEL: @${{.*}}testInterpolationOfExistentialsL_
611+
func testInterpolationOfExistentials(h: Logger, p: Proto) {
612+
h.debug("A protocol's property \(p.property)")
613+
}
614+
615+
// CHECK-LABEL: @${{.*}}testInterpolationOfGenericsL_
616+
func testInterpolationOfGenerics<T : Proto>(h: Logger, p: T) {
617+
h.debug("A generic argument's property \(p.property)")
618+
}
619+
}
620+

0 commit comments

Comments
 (0)