Skip to content

Commit ab2fe45

Browse files
committed
ComputeSideEffects: checking for unknown argument uses need to consider type which contain raw pointers
1 parent dbb4d4d commit ab2fe45

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ private struct ArgumentEscapingWalker : ValueDefUseWalker, AddressDefUseWalker {
380380
mutating func hasUnknownUses(argument: FunctionArgument) -> Bool {
381381
if argument.type.isAddress {
382382
return walkDownUses(ofAddress: argument, path: UnusedWalkingPath()) == .abortWalk
383-
} else if argument.hasTrivialType {
383+
} else if argument.hasTrivialNonPointerType {
384384
return false
385385
} else {
386386
return walkDownUses(ofValue: argument, path: UnusedWalkingPath()) == .abortWalk

test/SILOptimizer/side_effects.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,3 +1113,22 @@ bb0(%0 : $@callee_guaranteed () -> ()):
11131113
return %1 : $Builtin.Int1
11141114
}
11151115

1116+
// CHECK-LABEL: sil @test_enum_and_p2a
1117+
// CHECK-NEXT: [%0: write v**.c*.v**]
1118+
// CHECK-NEXT: [global: write,deinit_barrier]
1119+
// CHECK-NEXT: {{^[^[]}}
1120+
sil @test_enum_and_p2a : $@convention(thin) (Optional<UnsafeMutablePointer<Int>>, Int) -> () {
1121+
bb0(%0 : $Optional<UnsafeMutablePointer<Int>>, %1 : $Int):
1122+
switch_enum %0 : $Optional<UnsafeMutablePointer<Int>>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
1123+
bb1(%2 : $UnsafeMutablePointer<Int>):
1124+
%3 = struct_extract %2 : $UnsafeMutablePointer<Int>, #UnsafeMutablePointer._rawValue
1125+
%4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Int
1126+
store %1 to %4 : $*Int
1127+
br bb3
1128+
bb2:
1129+
br bb3
1130+
bb3:
1131+
%r = tuple()
1132+
return %r : $()
1133+
}
1134+

0 commit comments

Comments
 (0)