qir-alliance/qcor

Quantum gate declaration: segmentation fault

moar55 opened this issue · 1 comments

Running this code causes a segmentation fault:

OPENQASM 3;
gate cphase(θ) a, b
{
  U(0, 0, θ / 2) a;
  CX a, b;
  U(0, 0, -θ / 2) b;
  CX a, b;
  U(0, 0, θ / 2) b;
}

I've had a quick look at this today. The segmentation fault is due to this line:
https://github.com/ORNL-QCI/qcor/blob/master/mlir/parsers/qasm3/visitor_handlers/quantum_types_handler.cpp#L160

This gate definition has a floating point argument (theta) and the SSA tracking is not appropriate for this case.
A potential fix is to add a conditional check right after the for loop:
https://github.com/ORNL-QCI/qcor/blob/master/mlir/parsers/qasm3/visitor_handlers/quantum_types_handler.cpp#L154

If an argument is not of Qubit type, just add it to the return list without doing SSA tracing.