Commit 1dae38ee authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files
parent 0230a552
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -190,6 +190,40 @@ QCOR_EXPECT_TRUE(val2 == 5);
  EXPECT_FALSE(qcor::execute(uint_index, "uint_index"));
}

// Coverage for https://github.com/ORNL-QCI/qcor/issues/211 as well
TEST(qasm3VisitorTester, checkEarlyReturnWith211) {
  const std::string uint_index = R"#(OPENQASM 3;
include "qelib1.inc";

def generate_number(int[64]: count) -> int[64] {
  for i in [0:count] {
    if (i > 10) {
      print("Return at ", i);
      return 3;
    }
    print("i =", i);
  }

  print("make it to the end");
  return count;  
}

int[64] arg_val = 7;
int[64] val1 = generate_number(arg_val);
print("Result 1 =", val1);
QCOR_EXPECT_TRUE(val1 == arg_val);
// Call it with 20 -> activate the early return
int[64] val2 = generate_number(20);
print("Result 2 =", val2);
QCOR_EXPECT_TRUE(val2 == 3);
)#";
  auto mlir = qcor::mlir_compile(uint_index, "uint_index",
                                 qcor::OutputType::MLIR, false);
  std::cout << mlir << "\n";
  EXPECT_FALSE(qcor::execute(uint_index, "uint_index"));
}


TEST(qasm3VisitorTester, checkIqpewithIf) {
  const std::string qasm_code = R"#(OPENQASM 3;
include "qelib1.inc";
+5 −2
Original line number Diff line number Diff line
@@ -435,9 +435,12 @@ antlrcpp::Any qasm3_visitor::visitReturnStatement(
            value = builder.create<mlir::LoadOp>(location, value, zero_index);
          }
        } else {
          // If value is a memref val, load it.
          if (value.getType().isa<mlir::MemRefType>()) {
            value =
                builder.create<mlir::LoadOp>(location, value); //, zero_index);
          }
        }
      } else {
        printErrorMessage("We do not return memrefs from subroutines.",
                          context);