microsoft / qsharp-compiler

Q# compiler, command line tool, and Q# language server
https://docs.microsoft.com/quantum
MIT License
684 stars 172 forks source link

Fix QIR codegen for repeat loop with array variable #1587

Closed bamarsha closed 1 year ago

bamarsha commented 1 year ago

At the end of the repeat scope, codegen loops through the results variable to unreference its items. This accesses the length of the array, which is a cached LLVM value. But the value is from a basic block that is not a predecessor of the current block. To make the cache realize that it's invalid, wrap the contBlock scope exiting in a codegen "branch."

Closes #1581.