1

All went fine until my project won't compile.I see those things on two of my files.

Terminator found in the middle of a basic block!
label %50
LLVM ERROR: Broken function found, compilation aborted!


Terminator found in the middle of a basic block!
label %71
LLVM ERROR: Broken function found, compilation aborted!

And the error the compiler give

Command /Applications/Xcode-beta 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

I tried solving it, but no success. Older version of the files compile. The problem is in the files,but what is the terminator?

Where is the problem?

EDIT

Here is some code, the classes are big

LandscapeViewController

 import UIKit

        class LandscapeViewController: UIViewController,UIScrollViewDelegate {

            // MARK: Properties
            @IBOutlet weak var scrollView: UIScrollView!
            @IBOutlet weak var pageControl: UIPageControl!

            var search: Search!
            private var firstTime = true
            private var downloadTasks = [NSURLSessionDownloadTask]()

            @IBAction func pageChange(sender: UIPageControl){
                UIView.animateWithDuration(0.3, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
                    self.scrollView.contentOffset = CGPoint(x: self.scrollView.bounds.size.width * CGFloat(sender.currentPage), y: 0)
                    }, completion: nil )
            }



            // MARK: Buttons
            private func tileButtons(searchResults: [SearchResult]){
                var columnsPerPage = 5
                var rowsPerPage = 3
                var itemWidth: CGFloat = 96
                var itemHeight: CGFloat = 88
                var marginX: CGFloat = 0
                var marginY: CGFloat = 20
                let buttonWidth: CGFloat = 82
                let buttonHeight: CGFloat = 82

                let scrollViewWidth = scrollView.bounds.size.width

                switch scrollViewWidth{
                case 568:
                    columnsPerPage = 6
                    itemWidth = 94
                    marginX = 2
                case 667:
                    columnsPerPage = 7
                    itemWidth = 95
                    itemHeight = 98
                    marginX = 1
                    marginY = 29
                case 736:
                    columnsPerPage = 8
                    rowsPerPage = 4
                    itemWidth = 92
                default:
                    break
                }

                let paddingHorz = (itemWidth - buttonWidth)/2
                let paddingVert = (itemHeight - buttonHeight)/2

                var row = 0
                var column = 0
                var x = marginX

                for (index,searchResult) in searchResults.enumerate(){

                    let button = UIButton(type: .Custom)
                    button.setBackgroundImage(UIImage(named: "LandscapeButton"), forState: .Normal)

                    downloadImageForSearchResult(searchResult, andPlaceOnButton: button)

                    button.tag = 2000 + index
                    button.addTarget(self, action: Selector("buttonPressed:"), forControlEvents: .TouchUpInside)

                    button.backgroundColor = UIColor.whiteColor()

                    button.frame = CGRect(x: x + paddingHorz, y: marginY + CGFloat(row)*itemHeight + paddingVert, width: buttonWidth, height: buttonHeight)
                    scrollView.addSubview(button)
                    ++row
                    if row == rowsPerPage{
                        row = 0
                        ++column
                        x += itemWidth

                        if column == columnsPerPage{
                            column = 0
                            x += marginX * 2
                        }

                    }


                }

                let buttonsPerPage = columnsPerPage * rowsPerPage
                let numPages = 1 + (searchResults.count - 1) / buttonsPerPage
                pageControl.numberOfPages = numPages
                pageControl.currentPage = 0

                scrollView.contentSize = CGSize(width: CGFloat(numPages) * scrollViewWidth, height: scrollView.bounds.size.height)


            }

            private func downloadImageForSearchResult(searchResult: SearchResult,andPlaceOnButton button: UIButton){
                if let url = NSURL(string: searchResult.artworkURL60){
                    let session = NSURLSession.sharedSession()
                    let downloadTask = session.downloadTaskWithURL(url,completionHandler: { [weak button] url, response, error in
                        if error == nil && url != nil{
                            if let data = NSData(contentsOfURL: url!){
                                if let image = UIImage(data: data){
                                    let resizedImage = image.resizedImageWithBounds(CGSize(width: 60, height: 60))
                                    dispatch_async(dispatch_get_main_queue()){
                                        if let button = button{
                                            button.setImage(resizedImage, forState: .Normal)
                                        }
                                    }
                                }
                            }
                        }
                        })
                    downloadTasks.append(downloadTask!)
                    downloadTask?.resume()
                }
            }

            override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
                if segue.identifier == "ShowDetail"{
                    switch search.state{
                    case .Results(let list):
                        let destinationViewController = segue.destinationViewController as! DetailViewController
                        let searchResult = list[sender!.tag - 2000]
                        destinationViewController.searchResult = searchResult
                    default:
                        break
                    }
                }
            }

            func buttonPressed(sender: UIButton){
                performSegueWithIdentifier("ShowDetail", sender: sender)
            }

            // MARK: UIScrollViewDelegate

            func scrollViewDidScroll(scrollView: UIScrollView) {
                let width = scrollView.bounds.size.width
                let currentPage = Int((scrollView.contentOffset.x + width/2) / width)
                pageControl.currentPage = currentPage
            }

            // MARK: Lifecycle

            override func viewDidLoad() {
                super.viewDidLoad()
                pageControl.numberOfPages = 0

                scrollView.backgroundColor = UIColor(patternImage: UIImage(named: "LandscapeBackground")!)


                view.removeConstraints(view.constraints)
                view.translatesAutoresizingMaskIntoConstraints = true

                pageControl.removeConstraints(pageControl.constraints)
                pageControl.translatesAutoresizingMaskIntoConstraints = true

                scrollView.removeConstraints(scrollView.constraints)
                scrollView.translatesAutoresizingMaskIntoConstraints = true

                // Do any additional setup after loading the view.
            }

            override func viewWillLayoutSubviews() {
                super.viewWillLayoutSubviews()


                scrollView.frame = view.bounds

                pageControl.frame = CGRect(x: 0, y: view.frame.size.height - pageControl.frame.size.height, width: view.frame.size.width, height: pageControl.frame.size.height)

                if firstTime{
                    firstTime = false
                    switch search.state{
                    case .NotSearchedYet:
                        break
                    case .Loading:
                        showSpinner()
                    case .NoResults:
                        showNothingFoundLabel()
                    case.Results(let list):
                        tileButtons(list)
                    }
                }

            }

            private func showNothingFoundLabel() {
                let label = UILabel(frame: CGRect.zeroRect)
                label.text = "Nothing Found"

                label.backgroundColor = UIColor.clearColor()
                label.textColor = UIColor.whiteColor()

                label.sizeToFit()

                var rect = label.frame
                rect.size.width = ceil(rect.size.width/2) * 2
                rect.size.height = ceil(rect.size.height/2) * 2
                label.frame = rect

                label.center = CGPoint(x: CGRectGetMidX(scrollView.bounds), y: CGRectGetMidY(scrollView.bounds))

                view.addSubview(label)
            }

            private func showSpinner(){
                let spinner = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
                spinner.center = CGPoint(x: CGRectGetMidX(scrollView.bounds) + 0.5, y: CGRectGetMidY(scrollView.bounds) + 0.5)

                spinner.tag = 1000
                view.addSubview(spinner)
                spinner.startAnimating()
            }

            func searchResultsRecived(){
                hideSpinner()

                switch search.state {
                case .NotSearchedYet, .Loading:
                    break
                case .NoResults:
                    showNothingFoundLabel()
                case .Results(let list):
                    tileButtons(list)
                }

            }

            private func hideSpinner(){
                view.viewWithTag(1000)?.removeFromSuperview()
            }

            override func didReceiveMemoryWarning() {
                super.didReceiveMemoryWarning()
                // Dispose of any resources that can be recreated.
            }


            deinit{
                print("deinit \(self)")

                for task in downloadTasks{
                    task.cancel()
                }
            }

            /*
            // MARK: - Navigation

            // In a storyboard-based application, you will often want to do a little preparation before navigation
            override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            // Get the new view controller using segue.destinationViewController.
            // Pass the selected object to the new view controller.
            }
            */

        }

SearchViewController

import UIKit

            class SearchViewController: UIViewController,UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate {


            private struct TableViewCellIdentifier {
                static let searchResultCell = "SearchResultCell"
                static let nothingFoundCell = "NothingFoundCell"
                static let loadingCell = "LoadingCell"
            }

            // MARK: LandscapeViewController
            override func willTransitionToTraitCollection(newCollection: UITraitCollection, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
                super.willTransitionToTraitCollection(newCollection, withTransitionCoordinator: coordinator)

                switch newCollection.verticalSizeClass{
                case .Compact:
                    showLandscapeViewWithCoordinator(coordinator)
                case .Regular,.Unspecified:
                    hideLandscapeViewWithCoordinator(coordinator)

                }
            }

            private func showLandscapeViewWithCoordinator(coordinator: UIViewControllerTransitionCoordinator){
                precondition(landscapeViewController == nil)

                landscapeViewController = storyboard?.instantiateViewControllerWithIdentifier("LandscapeViewController") as? LandscapeViewController


                if let controller = landscapeViewController{
                    controller.search = search

                    controller.view.frame = view.frame
                    controller.view.alpha = 0


                    view.addSubview(controller.view)
                    addChildViewController(controller)

                    coordinator.animateAlongsideTransition({ _ in
                        if self.presentedViewController != nil{
                            self.dismissViewControllerAnimated(true, completion: nil)
                        }
                        self.searchBar.resignFirstResponder()
                        controller.view.alpha = 1
                        }, completion: { _ in
                            controller.didMoveToParentViewController(self)
                    })


                }


            }

            private func hideLandscapeViewWithCoordinator(coordinator: UIViewControllerTransitionCoordinator){
                if let controller = landscapeViewController{
                    controller.willMoveToParentViewController(nil)

                    coordinator.animateAlongsideTransition({ _ in
                        controller.view.alpha = 0
                        }, completion: { _ in
                            if self.presentedViewController != nil {
                                self.dismissViewControllerAnimated(true, completion: nil)
                            }
                            controller.view.removeFromSuperview()
                            controller.removeFromParentViewController()
                            self.landscapeViewController = nil
                    })

                }
            }



            private func showNetworkError(){
                let alert = UIAlertController(title: "Whoops...", message: "There was an error reading from the iTunes Store. Please try again.", preferredStyle: .Alert)

                let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
                alert.addAction(action)

                presentViewController(alert, animated: true, completion: nil)

            }



            // MARK: Detail ViewController
            override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
                if segue.identifier == "ShowDetail" {
                    switch search.state{
                    case . Results(let list):
                        let indexPath = sender as! NSIndexPath
                        let searchResult = list[indexPath.row]
                        let detailViewController = segue.destinationViewController as! DetailViewController
                        detailViewController.searchResult = searchResult
                    default:
                        break
                    }
                }
            }


            // MARK: Properties
            @IBOutlet weak var searchBar: UISearchBar!
            @IBOutlet weak var tableView: UITableView!
            @IBOutlet weak var segmentedControl: UISegmentedControl!


            let search = Search()
            private var landscapeViewController: LandscapeViewController?

            // MARK: Methodes

            @IBAction func segmentedControl(sender: UISegmentedControl) {
                performSearch()
            }


            override func viewDidLoad() {
                super.viewDidLoad()
                tableView.contentInset = UIEdgeInsets(top: 108, left: 0, bottom: 0, right: 0)
                tableView.rowHeight = 80
                searchBar.becomeFirstResponder()
                configureNib(nibName: TableViewCellIdentifier.searchResultCell)
                configureNib(nibName: TableViewCellIdentifier.nothingFoundCell)
                configureNib(nibName: TableViewCellIdentifier.loadingCell)

            }

            private func configureNib(nibName nibName: String){
                let cellNib = UINib(nibName: nibName, bundle: nil)
                tableView.registerNib(cellNib, forCellReuseIdentifier: nibName)
            }


            // MARK: UISearchBarDelegate

            func searchBarSearchButtonClicked(searchBar: UISearchBar){
                performSearch()
            }

            private func performSearch() {
                if let category = Search.Category(rawValue: segmentedControl.selectedSegmentIndex){

                    search.performSearchForText(searchBar.text!, category: category){
                        success in
                        if !success{
                            self.showNetworkError()
                        }
                        if let controller = self.landscapeViewController{
                            controller.searchResultsRecived()
                        }

                        self.tableView.reloadData()
                    }

                    tableView.reloadData()
                    searchBar.resignFirstResponder()
                }
            }

            func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
                return .TopAttached
            }


            // MARK:  TableView

            // MARK: - UITableViewDataSource

            func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                switch search.state{
                case .NotSearchedYet:
                    return 0
                case .Loading,.NoResults:
                    return 1
                case .Results(let list):
                    return list.count
                }
            }

            func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

                switch search.state{
                case .NotSearchedYet:
                    fatalError("Should never get here")
                case .Loading:
                    let cell = tableView.dequeueReusableCellWithIdentifier(TableViewCellIdentifier.loadingCell, forIndexPath: indexPath)
                    let spinner = cell.viewWithTag(100) as! UIActivityIndicatorView
                    spinner.startAnimating()

                    return cell

                case .NoResults:
                    return tableView.dequeueReusableCellWithIdentifier(TableViewCellIdentifier.nothingFoundCell, forIndexPath: indexPath)
                case .Results(let list):
                    let cell = tableView.dequeueReusableCellWithIdentifier(TableViewCellIdentifier.searchResultCell, forIndexPath: indexPath) as! SearchResultCell

                    let searchResult = list[indexPath.row]

                    cell.configureForSearchResult(searchResult)

                    return cell

                }
            }

            // MARK: UITableViewDelegate

            func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
                tableView.deselectRowAtIndexPath(indexPath, animated: true)
                performSegueWithIdentifier("ShowDetail", sender: indexPath)
            }

            func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
                switch search.state{
                case .NotSearchedYet,.NoResults,.Loading:
                    return nil
                case .Results:
                    return indexPath
                }
            }
            }
4
  • Show us some code please. You have some block probably?
    – MGY
    Jul 3, 2015 at 7:38
  • @gyer Updated with code Jul 3, 2015 at 7:45
  • @SergiiMartynenkoJr I'm using Xcode 7, with Swift 2.0 in the project,and I'm on OS X 10.11.I can't have how to run Xcode 6.4 Jul 3, 2015 at 7:46
  • It's a problem at the level of LLVM. The reason probably is that one block in LLVM IR contains multiple br or ret.
    – tigertang
    May 16, 2019 at 16:05

2 Answers 2

2

This is a bug in the Swift compiler, you'll want to file a radar with Apple to report this. There's nothing you can do about it otherwise.

1
1

I had this error because I had a switch of an enum with a case that contain an Array payload (don't ask me why, I don't know).

I think the enum is the search state inside the tableView:cellForRowAtIndexPath: method of SearchViewController and the prepareForSegue: method of LandscapeViewController (the .Result case contain a list).

In my case, changing the payload to a Set instead of an Array worked. (as a workaroud until it's fixed)

5
  • Thank you. Unfortunately Sets don't have an index I can't can the right values out of them.But I removed all code that needed a value for an index and it compiles ,but the app doesn't have any functionality.From when the error appeared I doubted that something with the enum was the problem.I'll update the radar with the information you provided Jul 9, 2015 at 18:26
  • And sorry that you had to guess my data model.I think as workaround I can have a different property with that array,and access it when state is Results Jul 9, 2015 at 19:10
  • wrapping the result in a class work (a struct fails like an Array) Jul 10, 2015 at 8:06
  • It's better just having a property on that class rather then having to wrap the array in a class,because you need to access it from that.And because I already implemented that with a proper in the same class Jul 10, 2015 at 10:13
  • I know that from the adcdownload.apple.com/Developer_Tools/Xcode_7_beta_5/… page 16 Aug 7, 2015 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.