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-13941] SIL verification failure due to type mismatch #56338

Open
typesanitizer opened this issue Dec 8, 2020 · 4 comments
Open

[SR-13941] SIL verification failure due to type mismatch #56338

typesanitizer opened this issue Dec 8, 2020 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself SILGen Area → compiler: The SIL generation stage

Comments

@typesanitizer
Copy link

Previous ID SR-13941
Radar rdar://problem/72074537
Original Reporter @typesanitizer
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, SILGen
Assignee None
Priority Medium

md5: ee693d71877c859db8a8d1e836645381

relates to:

  • SR-8269 PHI node operands are not the same type as the result

Issue Description:

Configuration: main @ af8cf15 (release assert)

Crash message:

SIL verification failed: branch argument types do not match arguments for dest bb: std::equal(BI->getArgs().begin(), BI->getArgs().end(), BI->getDestBB()->args_begin(), [&](SILValue branchArg, SILArgument *bbArg) { return verifyBranchArgs(branchArg, bbArg); })
Verifying instruction:
     %4 = enum $Optional<@convention(c) (@owned Optional<AnyObject>) -> ()>, #Optional.some!enumelt, %3 : $@convention(c) (@owned Optional<AnyObject>) -> () // user: %5
->   br bb3(%4 : $Optional<@convention(c) (@owned Optional<AnyObject>) -> ()>) // id: %5

Reduced test case (compile with xcrun /path/to/swiftc tmp.swift -import-objc-header tmp.h -emit-sil -o /dev/null)

// tmp.h
typedef void MyConsumingFnType(id __attribute__((ns_consumed)));
MyConsumingFnType *getMyConsumingFn();

// tmp.swift
import Foundation

_ = getMyConsumingFn()
@typesanitizer
Copy link
Author

@swift-ci create

@typesanitizer
Copy link
Author

For this SIL verification failure, we can work around it by using -sil-verify-none for asserts builds.

@atrick
Copy link
Member

atrick commented Dec 18, 2020

You don't need the import foundation. Here's a simpler reproducer (no change to tmp.h):

public func foo() {
 _ = getMyConsumingFn()
} 

The type of the branch argument:
$Optional<@convention(c) (@owned Optional<AnyObject>) -> ()>

The type of the block argument:
$Optional<@convention(c) (Optional<AnyObject>) -> ()>

SILGen generates a switch for the Optional function type. It uses the @owned function type for the .some branch and the @unowned function type for the .none branch.

The SILVerifier is not happy about merging different function types. I'm not sure why SILGen is getting the function type wrong in the .none case.

sil [ossa] @$s3tmp3fooyyF : $@convention(thin) () -> () {
bb0:
 // function_ref getMyConsumingFn
 %0 = function_ref @getMyConsumingFn : $@convention(c) () -> Optional<@convention(c) (@owned Optional<AnyObject>) -> ()> // user: %1
 %1 = apply %0() : $@convention(c) () -> Optional<@convention(c) (@owned Optional<AnyObject>) -> ()> // user: %2
 switch_enum %1 : $Optional<@convention(c) (@owned Optional<AnyObject>) -> ()>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2 // id: %2

// %3 // user: %4
bb1(%3 : $@convention(c) (@owned Optional<AnyObject>) -> ()): // Preds: bb0
 %4 = enum $Optional<@convention(c) (@owned Optional<AnyObject>) -> ()>, #Optional.some!enumelt, %3 : $@convention(c) (@owned Optional<AnyObject>) -> () // user: %5
 br bb3(%4 : $Optional<@convention(c) (@owned Optional<AnyObject>) -> ()>) // id: %5

bb2: // Preds: bb0
 %6 = enum $Optional<@convention(c) (Optional<AnyObject>) -> ()>, #Optional.none!enumelt // user: %7
 br bb3(%6 : $Optional<@convention(c) (Optional<AnyObject>) -> ()>) // id: %7

bb3(%8 : $Optional<@convention(c) (Optional<AnyObject>) -> ()>): // Preds: bb2 bb1
 %9 = tuple () // user: %10
 return %9 : $() // id: %10
} // end sil function '$s3tmp3fooyyF'

@typesanitizer
Copy link
Author

I'm not sure if my changes with Clang function types in #34914 should fix this, I'll try to test it out.

@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 SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

2 participants