LLVM ERROR: when referencing an enclosing local function from within an enclosed closure

Originator:nathaniel.chandler
Number:rdar://19729179 Date Originated:02/05/2015
Status:Duplicate of 11266246 Resolved:
Product:swiftc/Xcode Product Version:Xcode versions 6A2008a, 6C86e
Classification:Serious Error Reproducible:Always
 
Summary:
In general, it is fine to refer to an enclosing function from the body of a closure that is defined within the function.  For example, the following code compiles without a hitch:

func function() {
    let closure: ()->() = { () -> Void in
        let f = function
        return
    }
}

However, the situation changes when the enclosing function is a local function.  This code yields

func outerfunction() {
    func function() {
        let closure: ()->() = { () -> Void in
            let l = function
            return
        }
    }
}

yields the following error:

Instruction does not dominate all uses!
  %6 = bitcast %SS* %0 to %swift.opaque*, !dbg !82
  %2 = bitcast %swift.opaque* %6 to i8*, !dbg !79
LLVM ERROR: Broken function found, compilation aborted!

Steps to Reproduce:
1. Feed swiftc the following text:

func outerfunction() {
    func function() {
        let closure: ()->() = { () -> Void in
            let l = function
            return
        }
    }
}

2. Witness the error.

Expected Results:
This code should perhaps compile without a hitch given that it works just fine for a non-local function.  Or perhaps not, I don't have the clearest sense of the intended semantics of local functions.  At any rate, this sort of error shouldn't be produced.

Actual Results:
Swift Compiler Error

Instruction does not dominate all uses!
  %6 = bitcast %SS* %0 to %swift.opaque*, !dbg !82
  %2 = bitcast %swift.opaque* %6 to i8*, !dbg !79
LLVM ERROR: Broken function found, compilation aborted!

Version:
6.1.1 (6A2008a)
6.2 Beta (6C86e)


Notes:


Configuration:


Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!