Skip to content

[Miscompile] Incorrect SSA aliasing #3769

Description

@amcasey

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)

Activity

  1. changed the title [-]Miscompile due to SSA aliasing[/-] [+][Miscompile] Incorrect SSA aliasing[/+] on Oct 2, 2026
  2. added a commit that references this issue on Oct 8, 2026
    3cba31a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions