@@ -326,7 +326,8 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
326326 break ;
327327 }
328328 default :
329- break ;
329+ throw qasm3::CompilerError (" Unsupported declaration type." ,
330+ stmt->debugInfo );
330331 }
331332
332333 // Handle initializer (measure only)
@@ -433,11 +434,12 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
433434 }
434435 for (size_t i = 0 ; i < qubits.size (); ++i) {
435436 // Use the MeasureOp directly to capture the i1 result for if/else
436- auto measureOp = MeasureOp::create (
437- builder, qubits[i], builder.getStringAttr (bits[i].registerName ),
438- builder.getI64IntegerAttr (bits[i].registerSize ),
439- builder.getI64IntegerAttr (bits[i].registerIndex ));
440- Value result = measureOp.getResult ();
437+ auto result =
438+ MeasureOp::create (builder, qubits[i],
439+ builder.getStringAttr (bits[i].registerName ),
440+ builder.getI64IntegerAttr (bits[i].registerSize ),
441+ builder.getI64IntegerAttr (bits[i].registerIndex ))
442+ .getResult ();
441443
442444 // Track the result for use in if/else conditions
443445 const auto & regName = bits[i].registerName ;
@@ -472,7 +474,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
472474 return ;
473475 }
474476
475- Value condition = translateCondition (stmt->condition , stmt->debugInfo );
477+ auto condition = translateCondition (stmt->condition , stmt->debugInfo );
476478 const bool hasElse = !stmt->elseStatements .empty ();
477479
478480 auto ifOp =
@@ -585,7 +587,8 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
585587 size_t ctrlIdx = 0 ;
586588 for (const auto & [n, positive] : ctrlSpec) {
587589 for (size_t i = 0 ; i < n; ++i, ++ctrlIdx) {
588- if (expandedOperands[ctrlIdx].size () != 1 ) {
590+ if (ctrlIdx >= expandedOperands.size () ||
591+ expandedOperands[ctrlIdx].size () != 1 ) {
589592 throw qasm3::CompilerError (" Control operand must be a single qubit." ,
590593 stmt->debugInfo );
591594 }
@@ -664,7 +667,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
664667
665668 // Check that no qubit appears twice across targets and controls.
666669 llvm::SmallDenseSet<Value> seen;
667- for (auto q : concat<const Value>(iterQubits, posControls, negControls)) {
670+ for (auto q : concat<Value>(iterQubits, posControls, negControls)) {
668671 if (!seen.insert (q).second ) {
669672 throw qasm3::CompilerError (" Duplicate qubit in gate '" + id +
670673 " ' operands." ,
@@ -817,7 +820,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
817820 if (const auto binaryExpr =
818821 std::dynamic_pointer_cast<qasm3::BinaryExpression>(condition)) {
819822 throw qasm3::CompilerError (
820- " Register comparisons cannot be translated to QC at the moment" ,
823+ " Register comparisons cannot be translated to QC at the moment. " ,
821824 debugInfo);
822825 }
823826
@@ -828,11 +831,17 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
828831 unaryExpr->op == qasm3::UnaryExpression::BitwiseNot);
829832 const auto idExpr = std::dynamic_pointer_cast<qasm3::IndexedIdentifier>(
830833 unaryExpr->operand );
831- Value bitVal = lookupBitValue (idExpr, debugInfo);
834+ if (!idExpr) {
835+ throw qasm3::CompilerError (" Unary expression has unsupported operand." ,
836+ debugInfo);
837+ }
838+ auto bitVal = lookupBitValue (idExpr, debugInfo);
832839 // Negate: XOR with true
833- Value trueVal = arith::ConstantOp::create (
834- builder, builder.getIntegerAttr (builder.getI1Type (), 1 ));
835- return arith::XOrIOp::create (builder, bitVal, trueVal);
840+ auto trueVal =
841+ arith::ConstantOp::create (
842+ builder, builder.getIntegerAttr (builder.getI1Type (), 1 ))
843+ .getResult ();
844+ return arith::XOrIOp::create (builder, bitVal, trueVal).getResult ();
836845 }
837846
838847 // Case 3: Single bit (c[0] — truthy)
0 commit comments