@@ -325,7 +325,8 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
325325 break ;
326326 }
327327 default :
328- break ;
328+ throw qasm3::CompilerError (" Unsupported declaration type." ,
329+ stmt->debugInfo );
329330 }
330331
331332 // Handle initializer (measure only)
@@ -430,11 +431,12 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
430431 }
431432 for (size_t i = 0 ; i < qubits.size (); ++i) {
432433 // Use the MeasureOp directly to capture the i1 result for if/else
433- auto measureOp = MeasureOp::create (
434- builder, qubits[i], builder.getStringAttr (bits[i].registerName ),
435- builder.getI64IntegerAttr (bits[i].registerSize ),
436- builder.getI64IntegerAttr (bits[i].registerIndex ));
437- Value result = measureOp.getResult ();
434+ auto result =
435+ MeasureOp::create (builder, qubits[i],
436+ builder.getStringAttr (bits[i].registerName ),
437+ builder.getI64IntegerAttr (bits[i].registerSize ),
438+ builder.getI64IntegerAttr (bits[i].registerIndex ))
439+ .getResult ();
438440
439441 // Track the result for use in if/else conditions
440442 const auto & regName = bits[i].registerName ;
@@ -469,7 +471,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
469471 return ;
470472 }
471473
472- Value condition = translateCondition (stmt->condition , stmt->debugInfo );
474+ auto condition = translateCondition (stmt->condition , stmt->debugInfo );
473475 const bool hasElse = !stmt->elseStatements .empty ();
474476
475477 auto ifOp =
@@ -580,7 +582,8 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
580582 size_t ctrlIdx = 0 ;
581583 for (const auto & [n, positive] : ctrlSpec) {
582584 for (size_t i = 0 ; i < n; ++i, ++ctrlIdx) {
583- if (expandedOperands[ctrlIdx].size () != 1 ) {
585+ if (ctrlIdx >= expandedOperands.size () ||
586+ expandedOperands[ctrlIdx].size () != 1 ) {
584587 throw qasm3::CompilerError (" Control operand must be a single qubit." ,
585588 stmt->debugInfo );
586589 }
@@ -659,7 +662,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
659662
660663 // Check that no qubit appears twice across targets and controls.
661664 llvm::SmallDenseSet<Value> seen;
662- for (auto q : concat<const Value>(iterQubits, posControls, negControls)) {
665+ for (auto q : concat<Value>(iterQubits, posControls, negControls)) {
663666 if (!seen.insert (q).second ) {
664667 throw qasm3::CompilerError (" Duplicate qubit in gate '" + id +
665668 " ' operands." ,
@@ -731,7 +734,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
731734 if (const auto binaryExpr =
732735 std::dynamic_pointer_cast<qasm3::BinaryExpression>(condition)) {
733736 throw qasm3::CompilerError (
734- " Register comparisons cannot be translated to QC at the moment" ,
737+ " Register comparisons cannot be translated to QC at the moment. " ,
735738 debugInfo);
736739 }
737740
@@ -742,11 +745,17 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
742745 unaryExpr->op == qasm3::UnaryExpression::BitwiseNot);
743746 const auto idExpr = std::dynamic_pointer_cast<qasm3::IndexedIdentifier>(
744747 unaryExpr->operand );
745- Value bitVal = lookupBitValue (idExpr, debugInfo);
748+ if (!idExpr) {
749+ throw qasm3::CompilerError (" Unary expression has unsupported operand." ,
750+ debugInfo);
751+ }
752+ auto bitVal = lookupBitValue (idExpr, debugInfo);
746753 // Negate: XOR with true
747- Value trueVal = arith::ConstantOp::create (
748- builder, builder.getIntegerAttr (builder.getI1Type (), 1 ));
749- return arith::XOrIOp::create (builder, bitVal, trueVal);
754+ auto trueVal =
755+ arith::ConstantOp::create (
756+ builder, builder.getIntegerAttr (builder.getI1Type (), 1 ))
757+ .getResult ();
758+ return arith::XOrIOp::create (builder, bitVal, trueVal).getResult ();
750759 }
751760
752761 // Case 3: Single bit (c[0] — truthy)
0 commit comments