Courtesy of copilot, confirmed using QIR generation in VS Code
"""Silent miscompile: RIR SSA aliases a `let` copy to the mutable it was copied from.
`h` should hold `n`'s value at the `let` (0 or 2, depending on the measurement),
but `map_store_to_dominated_ssa` records `h` as an alias of the variable `n`, so
the later `set n = 7` changes `h` too. The QIR records the constant 7 and never
uses the phi. There's no panic. The same root cause also panics in ssa_check
(repros/qsc_rir.passes.ssa_check.check_ssa_form.b27ba3e4).
Exits 0 while the miscompile reproduces. Found by opus-b14 in the panic hunt
(qsc_rir/src/passes/ssa_transform.rs).
"""
import re
import sys
from qdk import qsharp
SOURCE = """
namespace Demo {
operation Main() : Int {
use q0 = Qubit();
mutable n = 0;
if MResetZ(q0) == One { set n = 2; }
let h = n;
set n = 7;
h
}
}
"""
qsharp.init(target_profile=qsharp.TargetProfile.Adaptive_RIF)
qsharp.eval(SOURCE)
qir = str(qsharp.compile("Demo.Main()"))
recorded = re.findall(r"@__quantum__rt__int_record_output\(i64 ([^,]+),", qir)
print("int_record_output operands:", recorded)
if recorded == ["7"]:
print("REPRODUCED: QIR outputs 7 where h should be 0 or 2")
sys.exit(0)
print("NOT REPRODUCED")
sys.exit(1)
Courtesy of copilot, confirmed using QIR generation in VS Code