Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9431] "is" (and "as?") with an unknown target type calls swift_unknownRetain #51895

Open
Catfish-Man opened this issue Dec 7, 2018 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime

Comments

@Catfish-Man
Copy link
Member

Previous ID SR-9431
Radar rdar://problem/46823112
Original Reporter @Catfish-Man
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Runtime
Assignee None
Priority Medium

md5: 7dbc17c32ac03e0687b76fc3bcfdeb31

Issue Description:

Given the attached test case, I would not expect test2 to do any refcounting (and indeed, if I call it directly rather than indirecting through test3, it does not do any refcounting). SIL attached as well for convenience.

refcount.sil

main.swift

@Catfish-Man
Copy link
Member Author

Using swift@2c5ecb477, for some reason my update-checkout throws an exception when I try to dump the full checkout state

@belkadan
Copy link
Contributor

You're checking x is Any in the test3 case rather than x is NSNumber, but that still doesn't directly explain the retain.

@Catfish-Man
Copy link
Member Author

Manually imported into radar as 46823112

@gottesmm
Copy link
Member

This code is correct. See:

// test2<A>(_:_:)
sil hidden [noinline] @$S8refcount5test2ySbyXl_xtlF : $@convention(thin) <T> (@guaranteed AnyObject, @in_guaranteed T) -> Bool {
// %0                                             // users: %6, %4, %2
bb0(%0 : $AnyObject, %1 : $*T):
  debug_value %0 : $AnyObject, let, name "x", argno 1 // id: %2
  %3 = alloc_stack $AnyObject                     // users: %4, %15, %7
  store %0 to %3 : $*AnyObject                    // id: %4
  %5 = alloc_stack $T                             // users: %14, %9, %7

  // ===> This retain is a store strong into %3 which is needed b/c $AnyObject is coming in at +0 and we are casting at +1.
  strong_retain %0 : $AnyObject                   // id: %6
  // ===> This either destroys %3 /or/ performs a move of %3 into %5.
  checked_cast_addr_br take_always AnyObject in %3 : $*AnyObject to T in %5 : $*T, bb1, bb2 // id: %7

bb1:                                              // Preds: bb0
  // ===> This is the success case, so there is a live value in %5 that we need to destroy.
  %8 = integer_literal $Builtin.Int1, -1          // user: %10
  destroy_addr %5 : $*T                           // id: %9
  br bb3(%8 : $Builtin.Int1)                      // id: %10

bb2:                                              // Preds: bb0
  // ===> This is the failure case, so the cast destroyed the value for us.
  %11 = integer_literal $Builtin.Int1, 0          // user: %12
  br bb3(%11 : $Builtin.Int1)                     // id: %12

// %13                                            // user: %16
bb3(%13 : $Builtin.Int1):                         // Preds: bb2 bb1
  dealloc_stack %5 : $*T                          // id: %14
  dealloc_stack %3 : $*AnyObject                  // id: %15
  %16 = struct $Bool (%13 : $Builtin.Int1)        // user: %17
  return %16 : $Bool                              // id: %17
} // end sil function '$S8refcount5test2ySbyXl_xtlF'

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

3 participants