Skip to content

Commit b78f350

Browse files
committed
[+0-all] Teach silopt about normal guaranteed parameters so that it assumes that all modules have that flag enabled.
rdar://34222540
1 parent 0a41588 commit b78f350

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
open class Foo {
3+
open func doSomething(_ f: Foo) {}
4+
}
5+
6+
@_inlineable public func callFoo(f: Foo) {
7+
f.doSomething(f)
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/Inputs/guaranteed-normal-args.swift -o %t/TestModule.swiftmodule -emit-module -module-name TestModule
3+
// RUN: not --crash %target-sil-opt %s -I=%t -enable-guaranteed-normal-arguments
4+
5+
// This is a negative test
6+
7+
sil_stage canonical
8+
9+
import TestModule
10+
11+
sil @callFoo : $@convention(thin) (@owned Foo) -> () {
12+
bb0(%0 : $Foo):
13+
%1 = class_method %0 : $Foo, #Foo.doSomething!1 : (Foo) -> (Foo) -> (), $@convention(method) (@guaranteed Foo, @owned Foo) -> ()
14+
destroy_value %0 : $Foo
15+
%9999 = tuple()
16+
return %9999 : $()
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/Inputs/guaranteed-normal-args.swift -o %t/TestModule.swiftmodule -emit-module -module-name TestModule -enable-guaranteed-normal-arguments
3+
// RUN: %target-sil-opt %s -I=%t -enable-guaranteed-normal-arguments
4+
5+
// This is a positive test
6+
7+
sil_stage canonical
8+
9+
import TestModule
10+
11+
sil @callFoo : $@convention(thin) (@owned Foo) -> () {
12+
bb0(%0 : $Foo):
13+
%1 = class_method %0 : $Foo, #Foo.doSomething!1 : (Foo) -> (Foo) -> (), $@convention(method) (@guaranteed Foo, @guaranteed Foo) -> ()
14+
destroy_value %0 : $Foo
15+
%9999 = tuple()
16+
return %9999 : $()
17+
}

tools/sil-opt/SILOpt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ AssumeUnqualifiedOwnershipWhenParsing(
195195
"assume-parsing-unqualified-ownership-sil", llvm::cl::Hidden, llvm::cl::init(false),
196196
llvm::cl::desc("Assume all parsed functions have unqualified ownership"));
197197

198+
static llvm::cl::opt<bool>
199+
EnableGuaranteedNormalArguments(
200+
"enable-guaranteed-normal-arguments", llvm::cl::Hidden, llvm::cl::init(false),
201+
llvm::cl::desc("Assume that the input module was compiled with -enable-guaranteed-normal-arguments enabled"));
202+
198203
/// Regular expression corresponding to the value given in one of the
199204
/// -pass-remarks* command line flags. Passes whose name matches this regexp
200205
/// will emit a diagnostic.
@@ -315,6 +320,8 @@ int main(int argc, char **argv) {
315320
SILOpts.EnableSILOwnership = EnableSILOwnershipOpt;
316321
SILOpts.AssumeUnqualifiedOwnershipWhenParsing =
317322
AssumeUnqualifiedOwnershipWhenParsing;
323+
SILOpts.EnableGuaranteedNormalArguments =
324+
EnableGuaranteedNormalArguments;
318325

319326
if (EnforceExclusivity.getNumOccurrences() != 0) {
320327
switch (EnforceExclusivity) {

0 commit comments

Comments
 (0)