Skip to content

Commit a42bad2

Browse files
authored
Merge pull request #37934 from atrick/disable-weakwarn
Disable weak reference lifetime warnings by default.
2 parents b9ffc26 + 369ecb6 commit a42bad2

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,12 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
154154
P.addDiagnoseInfiniteRecursion();
155155
P.addYieldOnceCheck();
156156
P.addEmitDFDiagnostics();
157-
P.addDiagnoseLifetimeIssues();
158157

158+
// Only issue weak lifetime warnings for users who select object lifetime
159+
// optimization. The risk of spurious warnings outweighs the benefits.
160+
if (P.getOptions().EnableCopyPropagation) {
161+
P.addDiagnoseLifetimeIssues();
162+
}
159163
// Canonical swift requires all non cond_br critical edges to be split.
160164
P.addSplitNonCondBrCriticalEdges();
161165
}

test/SILOptimizer/definite_init_diagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func test2() {
106106
weak var w1 : SomeClass?
107107
_ = w1 // ok: default-initialized
108108

109-
// expected-warning@+4 {{weak reference will always be nil because the referenced object is deallocated here}}
109+
// Note: with -enable-copy-propagation, we also expect: {{weak reference will always be nil because the referenced object is deallocated here}}
110110
// expected-warning@+3 {{instance will be immediately deallocated because variable 'w2' is 'weak'}}
111111
// expected-note@+2 {{a strong reference is required to prevent the instance from being deallocated}}
112112
// expected-note@+1 {{'w2' declared here}}
@@ -1336,7 +1336,7 @@ func testDontDiagnoseUnownedImmediateDeallocationThroughStrong() {
13361336
weak var c1: SomeClass?
13371337
do {
13381338
let tmp = SomeClass()
1339-
c1 = tmp // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}}
1339+
c1 = tmp // Note: with -enable-copy-propagation, we also expect: {{weak reference will always be nil because the referenced object is deallocated here}}
13401340
}
13411341

13421342
unowned let c2: SomeClass
@@ -1347,7 +1347,7 @@ func testDontDiagnoseUnownedImmediateDeallocationThroughStrong() {
13471347

13481348
weak var c3: SomeClass?
13491349
let c3Tmp = SomeClass()
1350-
c3 = c3Tmp // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}}
1350+
c3 = c3Tmp // Note: with -enable-copy-propagation, we also expect: {{weak reference will always be nil because the referenced object is deallocated here}}
13511351

13521352
unowned let c4: SomeClass
13531353
let c4Tmp = SomeClass()

test/SILOptimizer/diagnose_lifetime_issues.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnose-lifetime-issues -o /dev/null -verify
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnose-lifetime-issues -o /dev/null -verify
22

33
import Builtin
44
import Swift

test/SILOptimizer/diagnose_lifetime_issues.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-sil %s -o /dev/null -verify
1+
// RUN: %target-swift-frontend -emit-sil -enable-copy-propagation %s -o /dev/null -verify
22

33
class Delegate {
44
func foo() { }

test/SILOptimizer/diagnose_lifetime_issues_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-sil %s -o /dev/null -verify
1+
// RUN: %target-swift-frontend -emit-sil %s -enable-copy-propagation -o /dev/null -verify
22
// REQUIRES: objc_interop
33

44
import Foundation

0 commit comments

Comments
 (0)