@@ -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)
@@ -431,11 +432,12 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
431432 }
432433 for (size_t i = 0 ; i < qubits.size (); ++i) {
433434 // Use the MeasureOp directly to capture the i1 result for if/else
434- auto measureOp = MeasureOp::create (
435- builder, qubits[i], builder.getStringAttr (bits[i].registerName ),
436- builder.getI64IntegerAttr (bits[i].registerSize ),
437- builder.getI64IntegerAttr (bits[i].registerIndex ));
438- Value result = measureOp.getResult ();
435+ auto result =
436+ MeasureOp::create (builder, qubits[i],
437+ builder.getStringAttr (bits[i].registerName ),
438+ builder.getI64IntegerAttr (bits[i].registerSize ),
439+ builder.getI64IntegerAttr (bits[i].registerIndex ))
440+ .getResult ();
439441
440442 // Track the result for use in if/else conditions
441443 const auto & regName = bits[i].registerName ;
@@ -470,7 +472,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
470472 return ;
471473 }
472474
473- Value condition = translateCondition (stmt->condition , stmt->debugInfo );
475+ auto condition = translateCondition (stmt->condition , stmt->debugInfo );
474476 const bool hasElse = !stmt->elseStatements .empty ();
475477
476478 auto ifOp =
@@ -581,7 +583,8 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
581583 size_t ctrlIdx = 0 ;
582584 for (const auto & [n, positive] : ctrlSpec) {
583585 for (size_t i = 0 ; i < n; ++i, ++ctrlIdx) {
584- if (expandedOperands[ctrlIdx].size () != 1 ) {
586+ if (ctrlIdx >= expandedOperands.size () ||
587+ expandedOperands[ctrlIdx].size () != 1 ) {
585588 throw qasm3::CompilerError (" Control operand must be a single qubit." ,
586589 stmt->debugInfo );
587590 }
@@ -660,7 +663,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
660663
661664 // Check that no qubit appears twice across targets and controls.
662665 llvm::SmallDenseSet<Value> seen;
663- for (auto q : concat<const Value>(iterQubits, posControls, negControls)) {
666+ for (auto q : concat<Value>(iterQubits, posControls, negControls)) {
664667 if (!seen.insert (q).second ) {
665668 throw qasm3::CompilerError (" Duplicate qubit in gate '" + id +
666669 " ' operands." ,
@@ -732,7 +735,7 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
732735 if (const auto binaryExpr =
733736 std::dynamic_pointer_cast<qasm3::BinaryExpression>(condition)) {
734737 throw qasm3::CompilerError (
735- " Register comparisons cannot be translated to QC at the moment" ,
738+ " Register comparisons cannot be translated to QC at the moment. " ,
736739 debugInfo);
737740 }
738741
@@ -743,11 +746,17 @@ class MLIRQasmImporter final : public qasm3::InstVisitor {
743746 unaryExpr->op == qasm3::UnaryExpression::BitwiseNot);
744747 const auto idExpr = std::dynamic_pointer_cast<qasm3::IndexedIdentifier>(
745748 unaryExpr->operand );
746- Value bitVal = lookupBitValue (idExpr, debugInfo);
749+ if (!idExpr) {
750+ throw qasm3::CompilerError (" Unary expression has unsupported operand." ,
751+ debugInfo);
752+ }
753+ auto bitVal = lookupBitValue (idExpr, debugInfo);
747754 // Negate: XOR with true
748- Value trueVal = arith::ConstantOp::create (
749- builder, builder.getIntegerAttr (builder.getI1Type (), 1 ));
750- return arith::XOrIOp::create (builder, bitVal, trueVal);
755+ auto trueVal =
756+ arith::ConstantOp::create (
757+ builder, builder.getIntegerAttr (builder.getI1Type (), 1 ))
758+ .getResult ();
759+ return arith::XOrIOp::create (builder, bitVal, trueVal).getResult ();
751760 }
752761
753762 // Case 3: Single bit (c[0] — truthy)
0 commit comments